class GreenLog::JsonWriter
A JSON-formated log.
Attributes
dest[R]
Public Class Methods
new(dest)
click to toggle source
# File lib/green_log/json_writer.rb, line 12 def initialize(dest) @dest = dest end
Public Instance Methods
<<(entry)
click to toggle source
# File lib/green_log/json_writer.rb, line 18 def <<(entry) raise ArgumentError, "GreenLog::Entry expected" unless entry.is_a?(GreenLog::Entry) dest << JSON.dump(entry_details(entry)) + "\n" end
Protected Instance Methods
entry_details(entry)
click to toggle source
# File lib/green_log/json_writer.rb, line 26 def entry_details(entry) { "severity" => Severity.name(entry.severity).upcase, "message" => entry.message, "data" => entry.data, "context" => entry.context, "exception" => exception_details(entry.exception), }.compact end
exception_details(exception)
click to toggle source
# File lib/green_log/json_writer.rb, line 36 def exception_details(exception) return nil if exception.nil? { "class" => exception.class.name, "message" => exception.message, "backtrace" => exception.backtrace, } end