lib/timber/logger.rb in timber-1.1.0 vs lib/timber/logger.rb in timber-1.1.1

- old
+ new

@@ -74,19 +74,28 @@ private def build_log_entry(severity, time, progname, msg) level = SEVERITY_MAP.fetch(severity) context_snapshot = CurrentContext.instance.snapshot + tags = extract_active_support_tagged_logging_tags - tags += [msg.delete(:tag)] if msg.is_a?(Hash) && msg.key?(:tag) - tags += msg.delete(:tags) if msg.is_a?(Hash) && msg.key?(:tags) + time_ms = nil + if msg.is_a?(Hash) + tags << msg.delete(:tag) if msg.key?(:tag) + tags += msg.delete(:tags) if msg.key?(:tags) + tags.uniq! + time_ms = msg.delete(:time_ms) if msg.key?(:time_ms) + + msg = msg[:message] if msg.length == 1 + end + event = Events.build(msg) if event - LogEntry.new(level, time, progname, event.message, context_snapshot, event, tags) + LogEntry.new(level, time, progname, event.message, context_snapshot, event, tags: tags, time_ms: time_ms) else - LogEntry.new(level, time, progname, msg, context_snapshot, nil, tags) + LogEntry.new(level, time, progname, msg, context_snapshot, nil, tags: tags, time_ms: time_ms) end end # Because of all the crazy ways Rails has attempted this we need this crazy method. def extract_active_support_tagged_logging_tags @@ -102,13 +111,13 @@ # logger = Timber::Logger.new(STDOUT) # logger.formatter = Timber::JSONFormatter.new # # Example message: # - # My log message @timber.io {"level":"info","dt":"2016-09-01T07:00:00.000000-05:00"} + # My log message @metadata {"level":"info","dt":"2016-09-01T07:00:00.000000-05:00"} # class HybridFormatter < Formatter - METADATA_CALLOUT = "@timber.io".freeze + METADATA_CALLOUT = "@metadata".freeze def call(severity, time, progname, msg) log_entry = build_log_entry(severity, time, progname, msg) metadata = log_entry.to_json(:except => [:message]) # use << for concatenation for performance reasons \ No newline at end of file