lib/timber/log_entry.rb in timber-2.6.2 vs lib/timber/log_entry.rb in timber-3.0.0
- old
+ new
@@ -9,11 +9,10 @@
# `Logger` and the log device that you set it up with.
class LogEntry #:nodoc:
BINARY_LIMIT_THRESHOLD = 1_000.freeze
DT_PRECISION = 6.freeze
MESSAGE_MAX_BYTES = 8192.freeze
- SCHEMA = "https://raw.githubusercontent.com/timberio/log-event-json-schema/v3.2.0/schema.json".freeze
attr_reader :context_snapshot, :event, :level, :message, :progname, :tags, :time
# Creates a log entry suitable to be sent to the Timber API.
# @param level [Integer] the log level / severity
@@ -39,11 +38,11 @@
@context_snapshot = context_snapshot
@event = event
end
# Builds a hash representation containing simple objects, suitable for serialization (JSON).
- def as_json(options = {})
+ def to_hash(options = {})
options ||= {}
hash = {
:level => level,
:dt => formatted_dt,
:message => message
@@ -52,19 +51,17 @@
if !tags.nil? && tags.length > 0
hash[:tags] = tags
end
if !event.nil?
- hash[:event] = event.as_json
+ hash.merge!(event)
end
if !context_snapshot.nil? && context_snapshot.length > 0
hash[:context] = context_snapshot
end
- hash[:"$schema"] = SCHEMA
-
if options[:only]
hash.select do |key, _value|
options[:only].include?(key)
end
elsif options[:except]
@@ -79,35 +76,20 @@
def inspect
to_s
end
def to_json(options = {})
- as_json(options).to_json
+ to_hash.to_json
end
def to_msgpack(*args)
- as_json.to_msgpack(*args)
+ to_hash.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_type}.#{event.type}"
- else
- "#{event_type}"
- end
-
- log_message = "#{message} [#{event_type}]"
- end
-
- log_message + "\n"
+ message + "\n"
end
private
def formatted_dt
@formatted_dt ||= time.iso8601(DT_PRECISION)
@@ -123,6 +105,6 @@
})
rescue Exception
nil
end
end
-end
\ No newline at end of file
+end