lib/timber/log_entry.rb in timber-2.0.24 vs lib/timber/log_entry.rb in timber-2.1.0.rc1

- old
+ new

@@ -1,7 +1,10 @@ require 'socket' +require "timber/contexts" +require "timber/events" + module Timber # Represents a new log entry into the log. This is an intermediary class between # `Logger` and the log device that you set it up with. class LogEntry #:nodoc: DT_PRECISION = 6.freeze @@ -30,22 +33,31 @@ @message = message.is_a?(String) ? message : message.inspect @tags = options[:tags] @time_ms = options[:time_ms] context_snapshot = {} if context_snapshot.nil? + + # Set the system context for each log entry since processes can be forked + # and the process ID could change. hostname = Socket.gethostname pid = Process.pid system_context = Contexts::System.new(hostname: hostname, pid: pid) context_snapshot[system_context.keyspace] = system_context.as_json @context_snapshot = context_snapshot @event = event end + # Builds a hash representation of containing simply objects, suitable for serialization. def as_json(options = {}) options ||= {} - hash = {:level => level, :dt => formatted_dt, :message => message, :tags => tags, - :time_ms => time_ms} + hash = { + :level => level, + :dt => formatted_dt, + :message => message, + :tags => tags, + :time_ms => time_ms + } if !event.nil? hash[:event] = event.as_json end \ No newline at end of file