Skip to content

Instantly share code, notes, and snippets.

@chiastolite
Created January 17, 2015 16:07
Show Gist options
  • Save chiastolite/fc367e280b20e4a5f961 to your computer and use it in GitHub Desktop.
Save chiastolite/fc367e280b20e4a5f961 to your computer and use it in GitHub Desktop.
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.name = "ruboty-fluent-logger"
spec.version = "1.0.0"
spec.authors = ["chiastolite"]
spec.email = ["chiastolite.1980@gmail.com"]
spec.summary = "foward all messages to fluentd"
spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0")
spec.require_paths = ["."]
spec.add_dependency 'fluent-logger'
end
require 'fluent-logger'
module Ruboty
module Handlers
class FluentLogger < Base
env :FLUENTD_HOST, 'Fluentd Host'
env :FLUENTD_PORT, 'Fluentd Port'
env :LOGGER_TAG, 'Fluentd Tag'
::Fluent::Logger::FluentLogger.open(nil, host: ENV['FLUENTD_HOST'], port: ENV['FLUENTD_PORT'])
on(
/.*/,
name: 'capture',
description: 'capture all messages.',
all: true
)
def capture(message)
::Fluent::Logger.post(ENV['LOGGER_TAG'], {from_name: message.from_name, body: message.body})
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment