lib/semantic_logger/log.rb in semantic_logger-3.0.1 vs lib/semantic_logger/log.rb in semantic_logger-3.1.0

- old
+ new

@@ -21,11 +21,11 @@ # # time # The time at which the log entry was created # # duration - # The time taken to complete a benchmark call + # The time taken to complete a measure call # # tags # Any tags active on the thread when the log call was made # # level_index @@ -33,15 +33,19 @@ # # exception # Ruby Exception object to log # # metric [Object] - # Object supplied when benchmark_x was called + # Object supplied when measure_x was called # # backtrace [Array<String>] # The backtrace captured at source when the log level >= SemanticLogger.backtrace_level - Log = Struct.new(:level, :thread_name, :name, :message, :payload, :time, :duration, :tags, :level_index, :exception, :metric, :backtrace) do + # + # metric_amount [Numeric] + # Used for numeric or counter metrics. + # For example, the number of inquiries or, the amount purchased etc. + Log = Struct.new(:level, :thread_name, :name, :message, :payload, :time, :duration, :tags, :level_index, :exception, :metric, :backtrace, :metric_amount) do MAX_EXCEPTIONS_TO_UNWRAP = 5 # Call the block for exception and any nested exception def each_exception # With thanks to https://github.com/bugsnag/bugsnag-ruby/blob/6348306e44323eee347896843d16c690cd7c4362/lib/bugsnag/notification.rb#L81 @@ -145,15 +149,16 @@ 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) + def payload_to_s + payload.inspect if has_payload? + end - # Colorize the payload if the AwesomePrint gem is loaded - payload.ai(multiline: false) rescue payload.inspect + # Returns [true|false] whether the log entry has a payload + def has_payload? + !(payload.nil? || (payload.respond_to?(:empty?) && payload.empty?)) end if defined? JRuby # Return the Time as a formatted string # JRuby only supports time in ms