Class: Dclog::Formatter
- Inherits:
-
Object
- Object
- Dclog::Formatter
- Defined in:
- lib/dclog/formatter.rb
Constant Summary collapse
- LOG_REGEX =
/^\[([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\]\s+(.+)$/.freeze
Instance Method Summary collapse
- #add_silencer(&block) ⇒ Object
- #call(severity, timestamp, progname, message) ⇒ Object
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
6 7 8 |
# File 'lib/dclog/formatter.rb', line 6 def initialize @silencers = [] end |
Instance Method Details
#add_silencer(&block) ⇒ Object
10 11 12 |
# File 'lib/dclog/formatter.rb', line 10 def add_silencer(&block) @silencers << block end |
#call(severity, timestamp, progname, message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dclog/formatter.rb', line 14 def call(severity, , progname, ) return if should_filter?() msg_regex = .match(LOG_REGEX) request_id = msg_regex.nil? ? nil : msg_regex[1] msg = msg_regex.nil? ? : msg_regex[2] "#{JSON.dump( severity: severity, date: timestamp.strftime("%Y-%m-%d %H:%M:%S"), caller: progname, request_id: request_id, message: msg )}\n" end |