Class: Kybus::Logger::Format::LogCreator
- Inherits:
-
Object
- Object
- Kybus::Logger::Format::LogCreator
- Defined in:
- lib/kybus/logger/format.rb
Overview
Format params:
- %time
- %sev
- %pid
- %tid
- %module: won't work well on singleton classes. Prints the name of the invoking module
- %json: Data object encoded as json default format: "%time,%sev,%pid,%tid,%module,%json"
Instance Attribute Summary collapse
-
#frmt ⇒ Object
readonly
Returns the value of attribute frmt.
Instance Method Summary collapse
-
#initialize(frmt, sev, time, mod) ⇒ LogCreator
constructor
A new instance of LogCreator.
- #log_data(data) ⇒ Object
Constructor Details
#initialize(frmt, sev, time, mod) ⇒ LogCreator
Returns a new instance of LogCreator.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kybus/logger/format.rb', line 19 def initialize(frmt, sev, time, mod) @frmt = frmt = { '%sev': sev, '%time': time, '%mod': mod, '%pid': Process.pid.to_s(16), '%tid': Thread.current.object_id.to_s(16) } end |
Instance Attribute Details
#frmt ⇒ Object (readonly)
Returns the value of attribute frmt.
17 18 19 |
# File 'lib/kybus/logger/format.rb', line 17 def frmt @frmt end |
Instance Method Details
#log_data(data) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/kybus/logger/format.rb', line 30 def log_data(data) entry = frmt.dup .each { |k, v| entry.gsub!(k.to_s, v.to_s) } # json is slower than the meta records, so it is better to replace # in a lazy way. # TODO: Move lazy tags to a plugin-based model. entry.gsub('%json', data.to_json) if frmt.include?('%json') end |