Module: Bitlogger::Loggable

Defined in:
lib/bitlogger/loggable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bitlogger_additionalObject

Returns the value of attribute bitlogger_additional.



3
4
5
# File 'lib/bitlogger/loggable.rb', line 3

def bitlogger_additional
  @bitlogger_additional
end

Instance Method Details

#add_bitlogger_additional_info(additional) ⇒ Object



5
6
7
# File 'lib/bitlogger/loggable.rb', line 5

def add_bitlogger_additional_info(additional)
  @bitlogger_additional = additional
end

#debug(msg) ⇒ Object



28
29
30
# File 'lib/bitlogger/loggable.rb', line 28

def debug(msg)
  self.llog(:debug, msg)
end

#error(msg, exception = nil) ⇒ Object



40
41
42
# File 'lib/bitlogger/loggable.rb', line 40

def error(msg, exception = nil)
  self.llog(:error, msg, exception)
end

#fatal(msg, exception = nil) ⇒ Object



44
45
46
# File 'lib/bitlogger/loggable.rb', line 44

def fatal(msg, exception = nil)
  self.llog(:fatal, msg, exception)
end

#info(msg) ⇒ Object



32
33
34
# File 'lib/bitlogger/loggable.rb', line 32

def info(msg)
  self.llog(:info, msg)
end

#llog(level, msg, exception = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bitlogger/loggable.rb', line 9

def llog(level, msg, exception = nil)
  @bitlogger_additional ||= {}

  exception_info = {}
  if exception.is_a?(Exception)
    exception_info[:exception_name]    = exception.class.name
    exception_info[:exception_message] = exception.message
    exception_info[:exception_trace]   = exception.backtrace.join("\n")
  end

  Bitlogger.logger.log(
      {
          :level     => level,
          :message   => msg,
          :timestamp => Time.now.to_i
      }.merge(exception_info).merge(@bitlogger_additional)
  )
end

#warn(msg, exception = nil) ⇒ Object



36
37
38
# File 'lib/bitlogger/loggable.rb', line 36

def warn(msg, exception = nil)
  self.llog(:warn, msg, exception)
end