Class: Lumberaxe::JSONFormatter

Inherits:
Logger::Formatter
  • Object
show all
Includes:
ActiveSupport::TaggedLogging::Formatter
Defined in:
lib/lumberaxe/json_formatter.rb

Instance Method Summary collapse

Instance Method Details

#call(severity, time, progname, data) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/lumberaxe/json_formatter.rb', line 9

def call(severity, time, progname, data)
  data = data.is_a?(Hash) ? format_data(data) : { message: data.to_s }

  {
    level: severity,
    time: time,
    progname: progname,
  }.merge(data).to_json.concat("\r\n")
end

#format_data(data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lumberaxe/json_formatter.rb', line 19

def format_data(data)
  data.merge!(current_tags.each_with_object({}) do |tag, hash|
                if tag.include?("=")
                  key, value = tag.split("=")
                  hash[key] = value
                else
                  hash[:tags] ||= []
                  hash[:tags] << key
                end
                hash
              end)
end