Class: Flnt::Logger

Inherits:
BasicObject
Defined in:
lib/flnt/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(init_tag) ⇒ Logger

Returns a new instance of Logger.



5
6
7
# File 'lib/flnt/logger.rb', line 5

def initialize(init_tag)
  @tag = init_tag
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/flnt/logger.rb', line 9

def method_missing(name, *args)
  return super if name.to_s =~ /(!|\?)$/

  @tag = [@tag, name.to_s].join('.')
  unless args.empty?
    emit! args.first
  end

  return self
end

Instance Method Details

#emit!(arg) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flnt/logger.rb', line 20

def emit!(arg)
  info = {}
  case arg
  when ::Hash
    info.merge! arg
  when ::String
    info[:message] = arg
  when ::Exception
    info[:error_class] = arg.class
    info[:message]     = arg.message
    info[:backtrace]   = arg.backtrace if arg.backtrace
  else
    info[:info] = arg
  end
  ::Fluent::Logger.post @tag, info
end