Class: Fluent::Logger::FluentLogger

Inherits:
LoggerBase show all
Defined in:
lib/fluent/logger/fluent.rb

Constant Summary collapse

BUFFER_LIMIT =
8*1024*1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from LoggerBase

#create_event, open

Constructor Details

#initialize(tag, host, port = 24224) ⇒ FluentLogger

Returns a new instance of FluentLogger.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent/logger/fluent.rb', line 25

def initialize(tag, host, port=24224)
  super()
  require 'msgpack'
  require 'socket'
  require 'monitor'
  require 'logger'
  @mon = Monitor.new

  @tag = tag

  @pending = nil
  @host = host
  @port = port
  connect!

  @limit = BUFFER_LIMIT
  @logger = ::Logger.new(STDERR)

  FluentLogger.close_on_exit(self)
end

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



46
47
48
# File 'lib/fluent/logger/fluent.rb', line 46

def limit
  @limit
end

#loggerObject

Returns the value of attribute logger.



46
47
48
# File 'lib/fluent/logger/fluent.rb', line 46

def logger
  @logger
end

Instance Method Details

#closeObject



53
54
55
56
57
58
59
60
61
# File 'lib/fluent/logger/fluent.rb', line 53

def close
  if @pending
    @logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}")
  end
  @con.close if @con
  @con = nil
  @pending = nil
  self
end

#post(tag, map) ⇒ Object



48
49
50
51
# File 'lib/fluent/logger/fluent.rb', line 48

def post(tag, map)
  time = Time.now.to_i
  write ["#{@tag}.#{tag}", time, map]
end