Class: Intranet::Logger
- Inherits:
-
WEBrick::BasicLog
- Object
- WEBrick::BasicLog
- Intranet::Logger
- Defined in:
- lib/intranet/logger.rb
Overview
The default logger for the Intranet. It is based on WEBrick::BasicLog
but adds timestamp and colors to the messages.
Instance Method Summary collapse
-
#<<(obj) ⇒ Object
Logs an object that responds to
to_s
at level INFO. -
#initialize(level = INFO) ⇒ Logger
constructor
Initializes a new logger for $stderr that outputs messages at
level
or higher. -
#log(level, msg) ⇒ Object
Logs a message at a given level if it is above the current log level.
Constructor Details
#initialize(level = INFO) ⇒ Logger
Initializes a new logger for $stderr that outputs messages at level
or higher. level
can be modified later (attribute accessor).
21 22 23 |
# File 'lib/intranet/logger.rb', line 21 def initialize(level = INFO) super($stderr, level) end |
Instance Method Details
#<<(obj) ⇒ Object
Logs an object that responds to to_s
at level INFO.
34 35 36 |
# File 'lib/intranet/logger.rb', line 34 def <<(obj) info(obj.to_s.chomp) end |
#log(level, msg) ⇒ Object
Logs a message at a given level if it is above the current log level.
28 29 30 |
# File 'lib/intranet/logger.rb', line 28 def log(level, msg) super(level, "#{COLOR[level]}#{Time.now.strftime('[%Y-%m-%d %H:%M:%S]')} #{msg}\033[0m") end |