Class: Log4r::FluentOutputter

Inherits:
Outputter
  • Object
show all
Defined in:
lib/log4r/fluent_outputter.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name, hash = {}) ⇒ FluentOutputter

Returns a new instance of FluentOutputter.



11
12
13
14
15
16
17
# File 'lib/log4r/fluent_outputter.rb', line 11

def initialize(_name, hash={})
  super(_name, hash)
  @tag = hash[:tag] || hash["tag"] || 'test'
  host = hash[:host] || hash["host"] || 'localhost'
  port = hash[:port] || hash["port"] || 24224
  @log = Fluent::Logger::FluentLogger.new(nil, host: host, port: port.to_i)
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



9
10
11
# File 'lib/log4r/fluent_outputter.rb', line 9

def log
  @log
end

#tagObject

Returns the value of attribute tag.



8
9
10
# File 'lib/log4r/fluent_outputter.rb', line 8

def tag
  @tag
end

Instance Method Details

#canonical_log(logevent) ⇒ Object



19
20
21
# File 'lib/log4r/fluent_outputter.rb', line 19

def canonical_log(logevent)
  @log.post(@tag, {l: logevent.level, d: logevent.data})
end