1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-28 18:29:37 +00:00
rackstash/lib/rackstash/formatter.rb
Holger Just d192db441a Retain the original message in a Message object
We only format and convert it after passing it through the formatter.
That way, we can ensure that the actually interesting formatted value
is valid.
2017-01-26 23:32:29 +01:00

35 lines
1.2 KiB
Ruby

# Copyright 2017 Holger Just
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'logger'
module Rackstash
# The default logging formatter which is responsible for formatting a single
# {Message} for the final emitted log event.
class Formatter < ::Logger::Formatter
# Return the formatted message from the following rules:
# * Strings passed to `msg` are returned with an added newline character at
# the end
# * Exceptions are formatted with their name, message and backtrace,
# separated by newline characters.
# * All other objects will be `inspect`ed with an added newline.
#
# @param _severity [Integer] the log severity, ignored.
# @param _time [Time] the time of the log message, ignored.
# @param _progname [String] the program name, ignored.
# @param msg [String, Exception, #inspect] the log message
# @return [String] the formatted message with a final newline character
def call(_severity, _time, _progname, msg)
"#{msg2str(msg)}\n"
end
end
class RawFormatter
def call(_severity, _timestamp, _progname, msg)
msg.is_a?(String) ? msg : msg.inspect
end
end
end