lib/ougai/formatters/bunyan.rb in ougai-1.4.1 vs lib/ougai/formatters/bunyan.rb in ougai-1.4.2
- old
+ new
@@ -2,19 +2,26 @@
require 'json'
module Ougai
module Formatters
class Bunyan < Base
+ attr_accessor :jsonize
+
+ def initialize
+ super
+ @jsonize = true
+ end
+
def call(severity, time, progname, data)
- JSON.generate({
+ dump({
name: progname || @app_name,
hostname: @hostname,
pid: $$,
level: to_level(severity),
- time: time.iso8601(3),
+ time: time,
v: 0
- }.merge(data)) + "\n"
+ }.merge(data))
end
def to_level(severity)
case severity
when 'INFO'
@@ -28,9 +35,17 @@
when 'ANY'
70
else # DEBUG
20
end
+ end
+
+ private
+
+ def dump(data)
+ return data unless @jsonize
+ data[:time] = data[:time].iso8601(3)
+ JSON.generate(data) + "\n"
end
end
end
end