class DailyLogger::Formatter
Default formatter for log messages
Constants
- Format
Attributes
datetime_format[RW]
Public Class Methods
new()
click to toggle source
# File lib/daily_logger/formatter.rb, line 8 def initialize @datetime_format = nil end
Public Instance Methods
call(time, msg, block_msg)
click to toggle source
# File lib/daily_logger/formatter.rb, line 12 def call(time, msg, block_msg) Format % [format_datetime(time), make_msg(msg, block_msg)] end
Private Instance Methods
format_datetime(time)
click to toggle source
# File lib/daily_logger/formatter.rb, line 17 def format_datetime(time) if @datetime_format.nil? time.strftime "%Y/%m/%d %H:%M:%S" else time.strftime @datetime_format end end
make_msg(*args)
click to toggle source
# File lib/daily_logger/formatter.rb, line 25 def make_msg(*args) msgs = Array.new args.each do |msg| str = msg2str msg next if str.nil? msgs.push str end msgs.join "\t" end
msg2str(msg)
click to toggle source
# File lib/daily_logger/formatter.rb, line 35 def msg2str(msg) return nil if msg.nil? return msg if msg.kind_of? ::String all_msg = [] msg.each do |m| case m when ::String all_msg << m when ::Array all_msg << m when ::Exception short_backtrace = m.backtrace[0,4] all_msg << [m.message, short_backtrace] else all_msg << m.inspect end end all_msg.flatten end