Class: U::Log::Compat

Inherits:
Object
  • Object
show all
Defined in:
lib/u-log/compat.rb

Overview

Backward-compatible with the stdlib Logger ruby-doc.org/stdlib-2.0/libdoc/logger/rdoc/Logger.html

Constant Summary collapse

LEVELS =
{
  0 => :debug,
  1 => :info,
  2 => :warn,
  3 => :error,
  4 => :fatal,
  5 => :unknown,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ulogger) ⇒ Compat

Returns a new instance of Compat.



16
17
18
# File 'lib/u-log/compat.rb', line 16

def initialize(ulogger)
  @ulogger = ulogger
end

Instance Attribute Details

#uloggerObject (readonly)

Returns the value of attribute ulogger.



14
15
16
# File 'lib/u-log/compat.rb', line 14

def ulogger
  @ulogger
end

Instance Method Details

#log(severity, message = nil, progname = nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/u-log/compat.rb', line 20

def log(severity, message = nil, progname = nil, &block)
  pri = LEVELS[severity] || severity
  if block_given?
    progname = message
    message = yield rescue $!
  end

  data = { pri: pri }
  data[:app] = progname if progname
  data[:msg] = message if message

  @ulogger.log(data)
end

#noopObject



41
# File 'lib/u-log/compat.rb', line 41

def noop(*); true end