lib/finapps/utils/logging.rb in finapps-0.5.0.pre vs lib/finapps/utils/logging.rb in finapps-0.5.1.pre
- old
+ new
@@ -1,11 +1,15 @@
module FinApps
module Logging
SEVERITY_LABEL = %w(DEBUG INFO WARN ERROR FATAL UNKNOWN)
PROTECTED_KEYS = %w(login password password_confirm password1 token)
+ FORMAT = "\033[%sm[%s#%d] %5s -- %s: %s\033[0m\n"
+ FORMAT_TAG = "\033[%sm[%s#%d] %5s -- %s: %s %s\033[0m\n"
+ SEVERITY_COLOR_MAP = {:debug => '0', :info => '32', :warn => '33', :error => '31', :fatal => '31', :unknown => '0;37'}
+
class << self;
attr_accessor :tag;
end
def logger=(logger)
@@ -19,13 +23,12 @@
require 'logger' unless defined?(::Logger)
::Logger.new(STDOUT).tap do |log|
log.progname = "#{self.class.to_s}"
log.formatter = proc do |severity, time, progname, msg|
Logging.tag.present? ?
- "[%s#%d] %5s -- %s: %s %s\n" % [format_datetime(time), $$, severity, progname, Logging.tag.to_s, msg2str(msg)] :
- "[%s#%d] %5s -- %s: %s\n" % [format_datetime(time), $$, severity, progname, msg2str(msg)]
-
+ FORMAT_TAG % [severity_to_color(severity), format_datetime(time), $$, severity, progname, Logging.tag.to_s, msg2str(msg)] :
+ FORMAT % [severity_to_color(severity), format_datetime(time), $$, severity, progname, msg2str(msg)]
end
end
end
end
@@ -74,9 +77,13 @@
when ::Exception
"#{ msg.message } (#{ msg.class })\n" << (msg.backtrace || []).join("\n")
else
msg.inspect
end
+ end
+
+ def severity_to_color(severity)
+ SEVERITY_COLOR_MAP[severity.downcase.to_sym]
end
end
end
\ No newline at end of file