Class: Semlogger::Formatter
- Defined in:
- lib/semlogger/formatter.rb
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
- #data2ser(data) ⇒ Object
- #entry(severity, time, progname, msg, tags, data) ⇒ Object
-
#initialize(tags, data) ⇒ Formatter
constructor
A new instance of Formatter.
- #obj2ser(obj) ⇒ Object
- #tags2list(tags) ⇒ Object
Constructor Details
#initialize(tags, data) ⇒ Formatter
Returns a new instance of Formatter.
2 3 4 |
# File 'lib/semlogger/formatter.rb', line 2 def initialize , data @tags, @data = , data end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
35 36 37 |
# File 'lib/semlogger/formatter.rb', line 35 def call severity, time, progname, msg [severity, time.xmlschema(9), progname, msg, , data].to_json + "\n" end |
#data2ser(data) ⇒ Object
18 19 20 21 |
# File 'lib/semlogger/formatter.rb', line 18 def data2ser data data = data ? data.dup : {} data.each {|k,v| data[k] = obj2ser v } end |
#entry(severity, time, progname, msg, tags, data) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/semlogger/formatter.rb', line 23 def entry severity, time, progname, msg, , data e = { lvl: severity, ts: time, } e[:prog] = progname if progname e[:tags] = if and not .empty? e[:data] = data if data and not data.empty? e[:msg] = msg e end |
#obj2ser(obj) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/semlogger/formatter.rb', line 6 def obj2ser obj case obj when Proc then obj.call else obj end end |
#tags2list(tags) ⇒ Object
13 14 15 16 |
# File 'lib/semlogger/formatter.rb', line 13 def = ? .dup : [] .map &method( :obj2ser) end |