Class: Logger
- Inherits:
-
Object
- Object
- Logger
- Defined in:
- lib/terrimporter/app_logger.rb
Constant Summary collapse
- LOG_LEVELS =
{:debug => 0, :info => 1, :warn => 2, :error=> 3, :fatal => 4}
- LOG_COLORS =
{:debug =>'33', :info =>'32', :warn =>'33', :error=>'31', :fatal =>'31'}
- LOG_FORMAT_UNIX =
more infos: wiki.archlinux.org/index.php/Color_Bash_Prompt 033[0m Text reset 033[0;37m White 033[032m Green 033[033m Yellow 033[031m Red 033[037m White %s => [datetime], %s => color, %-5s => severity, %s => message
"\033[0;37m %s \033[0m[\033[%sm%-5s\033[0m]: %s \n"
- LOG_FORMAT_WINDOWS =
"%s %s[%-5s]: %s \n"
- TIME_FORMAT =
"%H:%M:%S"
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#log_format ⇒ Object
Returns the value of attribute log_format.
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #format_datetime(time) ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #is_windows ⇒ Object
- #log(severity, message) ⇒ Object
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
26 27 28 29 |
# File 'lib/terrimporter/app_logger.rb', line 26 def initialize self.level = :debug self.log_format = is_windows ? LOG_FORMAT_WINDOWS : LOG_FORMAT_UNIX end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/terrimporter/app_logger.rb', line 5 def level @level end |
#log_format ⇒ Object
Returns the value of attribute log_format.
5 6 7 |
# File 'lib/terrimporter/app_logger.rb', line 5 def log_format @log_format end |
Instance Method Details
#debug(message) ⇒ Object
39 40 41 |
# File 'lib/terrimporter/app_logger.rb', line 39 def debug() log(:debug, ) end |
#error(message) ⇒ Object
31 32 33 |
# File 'lib/terrimporter/app_logger.rb', line 31 def error() log(:error, ) end |
#format_datetime(time) ⇒ Object
50 51 52 |
# File 'lib/terrimporter/app_logger.rb', line 50 def format_datetime(time) time.strftime(TIME_FORMAT) end |
#info(message) ⇒ Object
35 36 37 |
# File 'lib/terrimporter/app_logger.rb', line 35 def info() log(:info, ) end |
#is_windows ⇒ Object
22 23 24 |
# File 'lib/terrimporter/app_logger.rb', line 22 def is_windows !((Config::CONFIG['host_os'] =~ /mswin|mingw/).nil?) end |
#log(severity, message) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/terrimporter/app_logger.rb', line 43 def log(severity, ) return if LOG_LEVELS[severity] < LOG_LEVELS[self.level] color = is_windows ? '' : LOG_COLORS[severity] out = LOG_LEVELS[severity] >= LOG_LEVELS[:error] ? $stderr : $stdout out.puts(self.log_format % [format_datetime(Time.now), color, severity.to_s.upcase, ]) end |