Class: Huyegger::Formatter
- Inherits:
-
Object
- Object
- Huyegger::Formatter
- Defined in:
- lib/huyegger/formatter.rb
Constant Summary collapse
- SEVERITY_STR =
{ ::Logger::DEBUG => "DEBUG", ::Logger::INFO => "INFO", ::Logger::WARN => "WARN", ::Logger::ERROR => "ERROR", ::Logger::FATAL => "FATAL", ::Logger::UNKNOWN => "UNKNOWN" }
Instance Attribute Summary collapse
-
#original_formatter ⇒ Object
readonly
Returns the value of attribute original_formatter.
Instance Method Summary collapse
-
#call(severity, timestamp, progname, msg) ⇒ Object
This method is invoked when a log event occurs.
- #clear_context! ⇒ Object
- #context(context) ⇒ Object
-
#initialize(original_formatter) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(original_formatter) ⇒ Formatter
Returns a new instance of Formatter.
18 19 20 |
# File 'lib/huyegger/formatter.rb', line 18 def initialize(original_formatter) @original_formatter = original_formatter end |
Instance Attribute Details
#original_formatter ⇒ Object (readonly)
Returns the value of attribute original_formatter.
16 17 18 |
# File 'lib/huyegger/formatter.rb', line 16 def original_formatter @original_formatter end |
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
This method is invoked when a log event occurs
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/huyegger/formatter.rb', line 31 def call(severity, , progname, msg) msg = original_formatter.call(severity, , progname, msg) if original_formatter && String === msg = {} add_severity!(, severity) .merge!(Huyegger.stringify_keys(__context__)) (, msg) () "#{Huyegger.json_encoder.call(json_message)}\n" end |
#clear_context! ⇒ Object
22 23 24 |
# File 'lib/huyegger/formatter.rb', line 22 def clear_context! __context__.clear end |
#context(context) ⇒ Object
26 27 28 |
# File 'lib/huyegger/formatter.rb', line 26 def context(context) __context__.merge!(context) unless context.nil? end |