lib/semantic_logger/log.rb in semantic_logger-2.18.0 vs lib/semantic_logger/log.rb in semantic_logger-2.19.0
- old
+ new
@@ -122,9 +122,19 @@
# Strip the standard Rails colorizing from the logged message
def cleansed_message
message.to_s.gsub(/(\e(\[([\d;]*[mz]?))?)?/, '').strip
end
+ # Return the payload in text form
+ # Returns nil if payload is missing or empty
+ def payload_to_s(colorized = false)
+ return if payload.nil? || (payload.respond_to?(:empty?) && payload.empty?)
+ return payload.inspect if !colorized || !defined?(AwesomePrint) || !payload.respond_to?(:ai)
+
+ # Colorize the payload if the AwesomePrint gem is loaded
+ payload.ai(multiline: false) rescue payload.inspect
+ end
+
if defined? JRuby
# Return the Time as a formatted string
# JRuby only supports time in ms
def formatted_time
"#{time.strftime('%Y-%m-%d %H:%M:%S')}.#{'%03d' % (time.usec/1000)}"