Class: Loggability::Formatter::Structured

Inherits:
Loggability::Formatter show all
Defined in:
lib/loggability/formatter/structured.rb

Overview

Output logs as JSON.

Constant Summary collapse

LOG_FORMAT_VERSION =

The version of the format output

1

Instance Attribute Summary

Attributes inherited from Loggability::Formatter

#derivatives

Instance Method Summary collapse

Methods inherited from Loggability::Formatter

create, inherited

Instance Method Details

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

Format a message of the specified severity using the given time, progname, and message.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/loggability/formatter/structured.rb', line 20

def call( severity, time, progname, message )
	severity ||= 'DEBUG'
	time ||= Time.now
	entry = {
		'@version' => LOG_FORMAT_VERSION,
		'@timestamp' => time.iso8601( 3 ),
		'level' => severity,
		'progname' => progname,
		'message' => message,
	}

	return JSON.generate( entry )
end