class DailyLogger
Attributes
device[RW]
formatter[RW]
level[RW]
Logging severity threshold (e.g. Logger::INFO
).
sev_threshold[RW]
Logging severity threshold (e.g. Logger::INFO
).
sev_threshold=[RW]
Logging severity threshold (e.g. Logger::INFO
).
Public Class Methods
new(name = nil)
click to toggle source
# File lib/daily_logger.rb, line 32 def initialize(name = nil) @name = name || 'all' @level = DEBUG @default_formatter = DailyLogger::Formatter.new @formatter = nil @log_adaptor = {} sev_label.each do |level| @log_adaptor[level] = DailyLogger::Adapter.new(level, @name) end end
Public Instance Methods
append(severity, msg = nil) { || ... }
click to toggle source
# File lib/daily_logger.rb, line 44 def append(severity, msg = nil, &block) severity ||= UNKNOWN if @log_adaptor.nil? or severity < @level return true end block_msg = nil if block_given? block_msg = yield end log_level = sev_label[severity] if @log_adaptor[log_level].nil? @log_adaptor[log_level] = DailyLogger::Adapter.new(log_level, @name) end @log_adaptor[log_level].write(log_level, format_message(Time.now, msg, block_msg)) true end
Also aliased as: log
close()
click to toggle source
# File lib/daily_logger.rb, line 113 def close sev_label.each do |level| next if @log_adaptor[level].nil? @log_adaptor[level].close end end
debug(*msg, &block)
click to toggle source
# File lib/daily_logger.rb, line 66 def debug(*msg, &block) append(DEBUG, msg, &block) end
debug?()
click to toggle source
Returns true
iff the current severity level allows for the printing of DEBUG
messages.
# File lib/daily_logger.rb, line 95 def debug?; @level <= DEBUG; end
error(*msg, &block)
click to toggle source
# File lib/daily_logger.rb, line 79 def error(*msg, &block) #msg = called_from.concat msg append(ERROR, msg, &block) end
error?()
click to toggle source
Returns true
iff the current severity level allows for the printing of ERROR
messages.
# File lib/daily_logger.rb, line 107 def error?; @level <= ERROR; end
fatal(*msg, &block)
click to toggle source
# File lib/daily_logger.rb, line 84 def fatal(*msg, &block) #msg = called_from.concat msg append(FATAL, msg, &block) end
fatal?()
click to toggle source
Returns true
iff the current severity level allows for the printing of FATAL
messages.
# File lib/daily_logger.rb, line 111 def fatal?; @level <= FATAL; end
info(*msg, &block)
click to toggle source
# File lib/daily_logger.rb, line 70 def info(*msg, &block) append(INFO, msg, &block) end
info?()
click to toggle source
Returns true
iff the current severity level allows for the printing of INFO
messages.
# File lib/daily_logger.rb, line 99 def info?; @level <= INFO; end
unknown(*msg, &block)
click to toggle source
# File lib/daily_logger.rb, line 89 def unknown(*msg, &block) append(UNKNOWN, msg, &block) end
warn(*msg, &block)
click to toggle source
# File lib/daily_logger.rb, line 74 def warn(*msg, &block) #msg = called_from.concat msg append(WARN, msg, &block) end
warn?()
click to toggle source
Returns true
iff the current severity level allows for the printing of WARN
messages.
# File lib/daily_logger.rb, line 103 def warn?; @level <= WARN; end
Private Instance Methods
called_from()
click to toggle source
# File lib/daily_logger.rb, line 123 def called_from caller(1)[1] =~ /(.*?):(\d+)(:in `(.*)')?/ file_name, line_num, function = $1, $2, $3 return [file_name, line_num, function] end
format_message(datetime, msg, block_msg)
click to toggle source
# File lib/daily_logger.rb, line 129 def format_message(datetime, msg, block_msg) (@formatter || @default_formatter).call(datetime, msg, block_msg) end
sev_label()
click to toggle source
# File lib/daily_logger.rb, line 121 def sev_label; [:debug, :info, :warn, :error, :fatal, :unknown]; end