Class: LogSanity::Formatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- LogSanity::Formatter
- Includes:
- ActiveSupport::TaggedLogging::Formatter
- Defined in:
- lib/log_sanity/formatter.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#call(severity, timestamp, progname, msg) ⇒ Object
tags are ignored when rendering as json however, tags are prepended when rendering with string_formatter.
Instance Attribute Details
#string_formatter ⇒ Object
35 36 37 38 |
# File 'lib/log_sanity/formatter.rb', line 35 def string_formatter return @string_formatter if defined?(@string_formatter) @string_formatter ||= ActiveSupport::Logger::SimpleFormatter.new end |
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
tags are ignored when rendering as json however, tags are prepended when rendering with string_formatter
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/log_sanity/formatter.rb', line 16 def call(severity, , progname, msg) if msg.is_a? Hash msg.reverse_merge!('at' => ) unless msg.key?('at') elsif msg.is_a? String if string_formatter msg = "#{tags_text}#{msg}" if .any? return string_formatter.call(severity, , progname, msg) else msg = {'at' => , 'message' => msg} end else msg = {'at' => , 'object' => msg.inspect} end msg['at'] = msg['at'].utc "#{msg.to_json}\n" end |