Class: Hickory::Formatters::JSON
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Hickory::Formatters::JSON
- Includes:
- ActiveSupport::TaggedLogging::Formatter
- Defined in:
- lib/hickory/formatters/json.rb
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
-
#initialize(options = {}) ⇒ JSON
constructor
A new instance of JSON.
Constructor Details
#initialize(options = {}) ⇒ JSON
Returns a new instance of JSON.
11 12 13 14 15 16 17 |
# File 'lib/hickory/formatters/json.rb', line 11 def initialize( = {}) @key_mapping = Hash.new.tap { |mapping| mapping[:message] = .fetch(:message_key, :message) mapping[:severity] = .fetch(:severity_key, :level) mapping[:timestamp] = .fetch(:timestamp_key, :timestamp) } end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hickory/formatters/json.rb', line 19 def call(severity, time, progname, msg) line = msg.tap { || [@key_mapping[:message]] = msg.delete(:message) unless @key_mapping[:message] == :message [@key_mapping[:timestamp]] = time [@key_mapping[:severity]] = severity [:progname] = progname unless progname.nil? [:tags] = unless .empty? } "#{line.to_json}\n" end |