Sha256: db8b0c50298eb2add81e23d2923cd5bca3f8a8f2c8f9ceb5630f1c60a505cf5f
Contents?: true
Size: 1.24 KB
Versions: 5
Compression:
Stored size: 1.24 KB
Contents
module Macmillan module Utils module Logger ## # A log formatter class for Logger objects. This formatter is used automatically # when you use the {Macmillan::Utils::Logger::Factory} class. # # === Usage: # # require 'macmillan/utils/logger' # # logger = Macmillan::Utils::Logger::Factory.build_logger(type, options) # class Formatter < ::Logger::Formatter ## # Builds a new instance of Formatter # # @param prefix [String] a string to prepend to all log lines # @return [Formatter] the configured formatter object # def initialize(prefix = nil) @format = '[%5s]: %s' @format = "#{prefix} #{@format}" if prefix end ## # Returns the log message formatted as desired # def call(severity, _time, _progname, msg) @format % [severity, msg2str(msg)] end protected def msg2str(msg) case msg when ::String "#{msg}\n" when ::Exception "#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n") else msg.inspect end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems