Class: Dokkit::Logging::Logger
- Inherits:
-
Object
- Object
- Dokkit::Logging::Logger
- Defined in:
- lib/dokkit/logging/logger.rb
Overview
Logger instance send log message to all its attached observers.
Instance Attribute Summary collapse
-
#last_message ⇒ Object
readonly
Returns the value of attribute last_message.
-
#level ⇒ Object
Returns the value of attribute level.
-
#observers ⇒ Object
readonly
Returns the value of attribute observers.
Instance Method Summary collapse
-
#attach(observer) ⇒ Object
Attach an observer to the logger instance.
-
#debug(text) ⇒ Object
Send a debug message to the observers.
-
#detach(observer) ⇒ Object
Detach the observer from the logger instance.
-
#error(text) ⇒ Object
Send an error message to the observers.
-
#info(text) ⇒ Object
Send an info message to observers.
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #message(message) ⇒ Object
-
#notify ⇒ Object
Notify log messages to all attached observers.
-
#warn(text) ⇒ Object
Send a warning message to the observers.
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
24 25 26 27 |
# File 'lib/dokkit/logging/logger.rb', line 24 def initialize @observers = [] @level = INFO end |
Instance Attribute Details
#last_message ⇒ Object (readonly)
Returns the value of attribute last_message.
21 22 23 |
# File 'lib/dokkit/logging/logger.rb', line 21 def @last_message end |
#level ⇒ Object
Returns the value of attribute level.
22 23 24 |
# File 'lib/dokkit/logging/logger.rb', line 22 def level @level end |
#observers ⇒ Object (readonly)
Returns the value of attribute observers.
20 21 22 |
# File 'lib/dokkit/logging/logger.rb', line 20 def observers @observers end |
Instance Method Details
#attach(observer) ⇒ Object
Attach an observer to the logger instance.
37 38 39 |
# File 'lib/dokkit/logging/logger.rb', line 37 def attach(observer) (@observers << observer).last end |
#debug(text) ⇒ Object
Send a debug message to the observers.
73 74 75 |
# File 'lib/dokkit/logging/logger.rb', line 73 def debug(text) ({ :text => text, :level => DEBUG }) if level >= DEBUG end |
#detach(observer) ⇒ Object
Detach the observer from the logger instance.
42 43 44 |
# File 'lib/dokkit/logging/logger.rb', line 42 def detach(observer) @observers.delete(observer) end |
#error(text) ⇒ Object
Send an error message to the observers.
63 64 65 |
# File 'lib/dokkit/logging/logger.rb', line 63 def error(text) ({ :text => text, :level => ERROR }) if level >= ERROR end |
#info(text) ⇒ Object
Send an info message to observers.
58 59 60 |
# File 'lib/dokkit/logging/logger.rb', line 58 def info(text) ({ :text => text, :level => INFO }) if level >= INFO end |
#message(message) ⇒ Object
51 52 53 54 55 |
# File 'lib/dokkit/logging/logger.rb', line 51 def () @last_message = notify @last_message end |
#notify ⇒ Object
Notify log messages to all attached observers.
47 48 49 |
# File 'lib/dokkit/logging/logger.rb', line 47 def notify @observers.each { |observer| observer.update } end |
#warn(text) ⇒ Object
Send a warning message to the observers.
68 69 70 |
# File 'lib/dokkit/logging/logger.rb', line 68 def warn(text) ({ :text => text, :level => WARNING }) if level >= WARNING end |