Class: Logtail::Logger::JSONFormatter

Inherits:
Formatter
  • Object
show all
Defined in:
lib/logtail/logger.rb

Overview

Structures your log messages into JSON.

logger = Logtail::Logger.new(STDOUT)
logger.formatter = Logtail::JSONFormatter.new

Example message:

{"level":"info","dt":"2016-09-01T07:00:00.000000-05:00","message":"My log message"}

Constant Summary

Constants inherited from Formatter

Formatter::EMPTY_ARRAY, Formatter::SEVERITY_MAP

Instance Method Summary collapse

Instance Method Details

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



116
117
118
119
# File 'lib/logtail/logger.rb', line 116

def call(severity, time, progname, msg)
  # use << for concatenation for performance reasons
  build_log_entry(severity, time, progname, msg).to_json << "\n"
end