Class: Moon::Logfmt::Logger
- Inherits:
-
Object
- Object
- Moon::Logfmt::Logger
- Includes:
- StdlibLoggable
- Defined in:
- lib/moon-logfmt/logger.rb
Overview
Basic Logger class for Logfmt writing The main functions are #write and #new #new will copy the current logger and append its context data
Constant Summary
Constants included from Severity
Severity::DEBUG, Severity::ERROR, Severity::FATAL, Severity::INFO, Severity::UNKNOWN, Severity::WARN
Instance Attribute Summary collapse
-
#formatter ⇒ Proc
A function which takes a key and value string and produces a string.
-
#io ⇒ IO, #puts
The underlaying IO to write to, the default is STDOUT.
-
#timestamp ⇒ Boolean
Whether to prepend timestamps to the logs.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Logger
constructor
A new instance of Logger.
- #initialize_copy(org) ⇒ self
-
#new(data) ⇒ Object
Creates a new context by forking the current logger.
-
#write(data) ⇒ Object
Writes a new log line.
Methods included from StdlibLoggable
#add, #debug, #error, #fatal, #info, #unknown, #warn
Constructor Details
Instance Attribute Details
#formatter ⇒ Proc
A function which takes a key and value string and produces a string
18 19 20 |
# File 'lib/moon-logfmt/logger.rb', line 18 def formatter @formatter end |
#io ⇒ IO, #puts
The underlaying IO to write to, the default is STDOUT
14 15 16 |
# File 'lib/moon-logfmt/logger.rb', line 14 def io @io end |
#timestamp ⇒ Boolean
Whether to prepend timestamps to the logs
22 23 24 |
# File 'lib/moon-logfmt/logger.rb', line 22 def @timestamp end |
Instance Method Details
#initialize_copy(org) ⇒ self
40 41 42 43 44 45 46 |
# File 'lib/moon-logfmt/logger.rb', line 40 def initialize_copy(org) @io = org.io @timestamp = org. @context = org.context.dup @formatter = org.formatter self end |
#new(data) ⇒ Object
Creates a new context by forking the current logger
84 85 86 |
# File 'lib/moon-logfmt/logger.rb', line 84 def new(data) dup.tap { |l| l.context.merge!(data) } end |
#write(data) ⇒ Object
Writes a new log line
75 76 77 78 79 |
# File 'lib/moon-logfmt/logger.rb', line 75 def write(data) pre = {} (pre) if @timestamp @io.puts format_context(pre.merge(context.merge(data))) end |