lib/berkeley_library/logging/formatters.rb in berkeley_library-logging-0.2.4 vs lib/berkeley_library/logging/formatters.rb in berkeley_library-logging-0.2.5

- old
+ new

@@ -1,6 +1,7 @@ require 'ougai' +require 'berkeley_library/logging/exception_serializer' module BerkeleyLibrary module Logging module Formatters @@ -39,25 +40,12 @@ end # ------------------------------------------------------------ # Private helper classes - module ErrorCauseSerializer - def serialize_exc(ex, serialized = Set.new) - super(ex).tap do |result| - next unless (cause = ex.cause) - next if (serialized << ex).include?(cause) # prevent circular references - - result[:cause] = serialize_exc(cause, serialized) - end - end - end - - private_constant :ErrorCauseSerializer - class Readable < Ougai::Formatters::Readable - include ErrorCauseSerializer + include ExceptionSerializer protected def create_err_str(data) return unless (err_hash = data.delete(:err)) @@ -69,14 +57,16 @@ def format_err(err_hash) " #{err_hash[:name]} (#{err_hash[:message]}):".tap do |msg| next unless (stack = err_hash[:stack]) - msg << "\n" - msg << (' ' * @trace_indent) - msg << stack + trace_indent = (' ' * @trace_indent) + trace_separator = "\n#{trace_indent}" + msg << trace_separator + msg << stack.join(trace_separator) + next unless (cause_hash = err_hash[:cause]) msg << "\n Caused by: " msg << format_err(cause_hash).strip end @@ -85,10 +75,10 @@ end private_constant :Readable class Bunyan < Ougai::Formatters::Bunyan include Ougai::Logging::Severity - include ErrorCauseSerializer + include ExceptionSerializer def _call(severity, time, progname, data) original_data = Formatters.ensure_hash(data) decolorized_data = Formatters.strip_ansi_escapes(original_data)