lib/semantic_logger/log.rb in semantic_logger-4.3.1 vs lib/semantic_logger/log.rb in semantic_logger-4.4.0
- old
+ new
@@ -57,11 +57,11 @@
@thread_name = Thread.current.name
@name = name
@time = Time.now
@tags = SemanticLogger.tags
@named_tags = SemanticLogger.named_tags
- @level_index = index.nil? ? SemanticLogger.level_to_index(level) : index
+ @level_index = index.nil? ? Levels.index(level) : index
end
# Assign named arguments to this log entry, supplying defaults where applicable
#
# Returns [true|false] whether this log entry should be logged
@@ -85,11 +85,16 @@
self.duration = duration
return false if (duration < min_duration) && exception.nil?
end
self.message = message
- self.payload = payload
+ if payload && payload.is_a?(Hash)
+ self.payload = payload
+ elsif payload
+ self.message = message.nil? ? payload.to_s : "#{message} -- #{payload}"
+ self.payload = nil
+ end
if exception
case log_exception
when :full
self.exception = exception
@@ -102,11 +107,11 @@
raise(ArgumentError, "Invalid value:#{log_exception.inspect} for argument :log_exception")
end
# On exception change the log level
if on_exception_level
self.level = on_exception_level
- self.level_index = SemanticLogger.level_to_index(level)
+ self.level_index = Levels.index(level)
end
end
if backtrace
self.backtrace = Utils.extract_backtrace(backtrace)
@@ -118,11 +123,10 @@
self.metric = metric
self.metric_amount = metric_amount
self.dimensions = dimensions
end
- self.payload = payload if payload&.size&.positive?
true
end
# Assign positional arguments to this log entry, supplying defaults where applicable
#
@@ -138,12 +142,13 @@
exception = message
message = nil
elsif exception.nil? && payload && payload.respond_to?(:backtrace) && payload.respond_to?(:message)
exception = payload
payload = nil
- elsif payload.is_a?(String)
+ elsif payload && !payload.is_a?(Hash)
message = message.nil? ? payload : "#{message} -- #{payload}"
+ payload = nil
end
# Add result of block as message or payload if not nil
if block_given? && (result = yield)
if result.is_a?(String)
@@ -277,10 +282,10 @@
# DEPRECATED
alias has_payload? payload?
# DEPRECATED
def formatted_time
- time.strftime(Formatters::Base::TIME_FORMAT)
+ time.strftime(Formatters::Base.build_time_format)
end
DeprecatedLogger = Struct.new(:host, :application)
# DEPRECATED: Use SemanticLogger::Formatters::Raw