lib/timber/logger.rb in timber-1.0.6 vs lib/timber/logger.rb in timber-1.0.7
- old
+ new
@@ -129,11 +129,21 @@
# {"level":"info","dt":"2016-09-01T07:00:00.000000-05:00","message":"My log message"}
#
class MsgPackFormatter < Formatter
def call(severity, time, progname, msg)
# use << for concatenation for performance reasons
- build_log_entry(severity, time, progname, msg).as_json.to_msgpack << "\n"
+ hash = build_log_entry(severity, time, progname, msg).as_json
+ to_msgpack(hash) << "\n"
end
+
+ private
+ def to_msgpack(msg)
+ begin
+ msg.to_msgpack
+ rescue NoMethodError
+ JSON.parse(JSON.generate(msg)).to_msgpack
+ end
+ end
end
# Creates a new Timber::Logger instances. Accepts the same arguments as `::Logger.new`.
# The only difference is that it default the formatter to {HybridFormatter}. Using
# a different formatter is easy. For example, if you prefer your logs in JSON.
\ No newline at end of file