lib/timber/log_entry.rb in timber-2.0.20 vs lib/timber/log_entry.rb in timber-2.0.21

- old
+ new

@@ -69,15 +69,39 @@ end Util::Hash.deep_compact(hash) end + def inspect + to_s + end + def to_json(options = {}) as_json(options).to_json end def to_msgpack(*args) as_json.to_msgpack(*args) + end + + # This is used when LogEntry objects make it to a non-Timber logger. + def to_s + log_message = message + + if !event.nil? + event_hash = event.as_json + event_type = event_hash.keys.first + + event_type = if event.is_a?(Events::Custom) + "event:#{event_type}.#{event.type}" + else + "event:#{event_type}" + end + + log_message = "#{message} [#{event_type}]" + end + + log_message + "\n" end private def formatted_dt @formatted_dt ||= time.iso8601(DT_PRECISION) \ No newline at end of file