Class: Howzit::ConsoleLogger
- Inherits:
-
Object
- Object
- Howzit::ConsoleLogger
- Defined in:
- lib/howzit/console_logger.rb
Overview
Console logging
Instance Attribute Summary collapse
-
#log_level ⇒ Object
Returns the value of attribute log_level.
Instance Method Summary collapse
-
#debug(msg) ⇒ Object
Write a message at debug level.
-
#error(msg) ⇒ Object
Write a message at error level.
-
#info(msg) ⇒ Object
Write a message at info level.
-
#initialize(level = nil) ⇒ ConsoleLogger
constructor
Init the console logging object.
-
#reset_level ⇒ Integer
Get the log level from options.
-
#warn(msg) ⇒ Object
Write a message at warn level.
-
#write(msg, level = :info) ⇒ Object
Write a message to the console based on the urgency level and user's log level setting.
Constructor Details
#initialize(level = nil) ⇒ ConsoleLogger
Init the console logging object
21 22 23 |
# File 'lib/howzit/console_logger.rb', line 21 def initialize(level = nil) @log_level = level.to_i || Howzit.[:log_level] end |
Instance Attribute Details
#log_level ⇒ Object
Returns the value of attribute log_level.
14 15 16 |
# File 'lib/howzit/console_logger.rb', line 14 def log_level @log_level end |
Instance Method Details
#debug(msg) ⇒ Object
Write a message at debug level
50 51 52 |
# File 'lib/howzit/console_logger.rb', line 50 def debug(msg) write msg, :debug end |
#error(msg) ⇒ Object
Write a message at error level
77 78 79 |
# File 'lib/howzit/console_logger.rb', line 77 def error(msg) write msg, :error end |
#info(msg) ⇒ Object
Write a message at info level
59 60 61 |
# File 'lib/howzit/console_logger.rb', line 59 def info(msg) write msg, :info end |
#reset_level ⇒ Integer
Get the log level from options
30 31 32 |
# File 'lib/howzit/console_logger.rb', line 30 def reset_level @log_level = Howzit.[:log_level] end |
#warn(msg) ⇒ Object
Write a message at warn level
68 69 70 |
# File 'lib/howzit/console_logger.rb', line 68 def warn(msg) write msg, :warn end |
#write(msg, level = :info) ⇒ Object
Write a message to the console based on the urgency level and user's log level setting
41 42 43 |
# File 'lib/howzit/console_logger.rb', line 41 def write(msg, level = :info) $stderr.puts msg if LOG_LEVELS[level] >= @log_level end |