lib/celluloid/logging/incident_logger.rb in celluloid-essentials-0.20.0.pre14 vs lib/celluloid/logging/incident_logger.rb in celluloid-essentials-0.20.0.pre15

- old
+ new

@@ -1,6 +1,6 @@ -require 'logger' +require "logger" module Celluloid # A logger that holds all messages in circular buffers, then flushes the buffers # when an event occurs at a configurable severity threshold. # # Unlike ruby's Logger, this class only supports a single progname. @@ -10,17 +10,17 @@ TRACE = -1 def severity_to_string(severity) case severity - when TRACE then 'TRACE' - when DEBUG then 'DEBUG' - when INFO then 'INFO' - when WARN then 'WARN' - when ERROR then 'ERROR' - when FATAL then 'FATAL' - when UNKNOWN then 'UNKNOWN' + when TRACE then "TRACE" + when DEBUG then "DEBUG" + when INFO then "INFO" + when WARN then "WARN" + when ERROR then "ERROR" + when FATAL then "FATAL" + when UNKNOWN then "UNKNOWN" end end end include Severity @@ -64,13 +64,11 @@ # add an event. def add(severity, message=nil, progname=nil, &block) progname ||= @progname severity ||= UNKNOWN - if severity < @level - return event.id - end + return event.id if severity < @level if message.nil? && !block_given? message = progname progname = @progname end @@ -86,19 +84,39 @@ @fallback_logger.error(ex) end end event.id end - alias :log :add + alias_method :log, :add # See docs for Logger#info - def trace (progname=nil, &block); add(TRACE, nil, progname, &block); end - def debug (progname=nil, &block); add(DEBUG, nil, progname, &block); end - def info (progname=nil, &block); add(INFO, nil, progname, &block); end - def warn (progname=nil, &block); add(WARN, nil, progname, &block); end - def error (progname=nil, &block); add(ERROR, nil, progname, &block); end - def fatal (progname=nil, &block); add(FATAL, nil, progname, &block); end - def unknown (progname=nil, &block); add(UNKNOWN, nil, progname, &block); end + def trace(progname=nil, &block) + add(TRACE, nil, progname, &block) + end + + def debug(progname=nil, &block) + add(DEBUG, nil, progname, &block) + end + + def info(progname=nil, &block) + add(INFO, nil, progname, &block) + end + + def warn(progname=nil, &block) + add(WARN, nil, progname, &block) + end + + def error(progname=nil, &block) + add(ERROR, nil, progname, &block) + end + + def fatal(progname=nil, &block) + add(FATAL, nil, progname, &block) + end + + def unknown(progname=nil, &block) + add(UNKNOWN, nil, progname, &block) + end def flush messages = [] @buffer_mutex.synchronize do @buffers.each do |progname, severities|