Class: Dokkit::Logging::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/dokkit/logging/logger.rb

Overview

Logger instance send log message to all its attached observers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

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_messageObject (readonly)

Returns the value of attribute last_message.



21
22
23
# File 'lib/dokkit/logging/logger.rb', line 21

def last_message
  @last_message
end

#levelObject

Returns the value of attribute level.



22
23
24
# File 'lib/dokkit/logging/logger.rb', line 22

def level
  @level
end

#observersObject (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)
  message({ :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)
  message({ :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)
  message({ :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 message(message)
  @last_message = message
  notify
  @last_message
end

#notifyObject

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)
  message({ :text => text, :level => WARNING }) if level >= WARNING
end