lib/berkeley_library/logging/formatters.rb in berkeley_library-logging-0.2.1 vs lib/berkeley_library/logging/formatters.rb in berkeley_library-logging-0.2.2

- old
+ new

@@ -21,10 +21,19 @@ return {} unless message return message if message.is_a?(Hash) { msg: message } end + + def decolorize(message) + return unless message + return message.uncolorize if message.is_a?(String) + return message.map { |v| decolorize(v) } if message.is_a?(Array) + return message.transform_values { |v| decolorize(v) } if message.is_a?(Hash) + + message + end end # ------------------------------------------------------------ # Private helper classes @@ -76,14 +85,15 @@ include Ougai::Logging::Severity include ErrorCauseSerializer def _call(severity, time, progname, data) original_data = Formatters.ensure_hash(data) + decolorized_data = Formatters.decolorize(original_data) # Ougai::Formatters::Bunyan replaces the human-readable severity string # with a numeric level, so we add it here as a separate attribute severity = ensure_human_readable(severity) - merged_data = { severity: severity }.merge(original_data) + merged_data = { severity: severity }.merge(decolorized_data) super(severity, time, progname, merged_data) end def ensure_human_readable(severity) return to_label(severity) if severity.is_a?(Integer)