Class: Synapse::Logger
- Inherits:
-
Object
- Object
- Synapse::Logger
- Defined in:
- lib/synapse/logger.rb
Constant Summary collapse
- INFO =
1- DEBUG =
0
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#progname ⇒ Object
Returns the value of attribute progname.
Class Method Summary collapse
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(dest) ⇒ Logger
constructor
A new instance of Logger.
- #rebind_to(logger) ⇒ Object
- #replay ⇒ Object
Constructor Details
#initialize(dest) ⇒ Logger
Returns a new instance of Logger.
20 21 22 23 |
# File 'lib/synapse/logger.rb', line 20 def initialize dest self.class.deferred_rebind self @messages = [] end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
18 19 20 |
# File 'lib/synapse/logger.rb', line 18 def level @level end |
#progname ⇒ Object
Returns the value of attribute progname.
18 19 20 |
# File 'lib/synapse/logger.rb', line 18 def progname @progname end |
Class Method Details
.deferred_rebind(logger) ⇒ Object
9 10 11 12 |
# File 'lib/synapse/logger.rb', line 9 def deferred_rebind logger @cache ||= [] @cache << ->(target) { logger.rebind_to target } end |
.rebind(logger) ⇒ Object
4 5 6 7 8 |
# File 'lib/synapse/logger.rb', line 4 def rebind logger @cache.each do |cached| cached.call logger end end |
Instance Method Details
#debug(message) ⇒ Object
32 33 34 35 |
# File 'lib/synapse/logger.rb', line 32 def debug return @logger.debug if @logger @messages << [:debug,] end |
#info(message) ⇒ Object
28 29 30 31 |
# File 'lib/synapse/logger.rb', line 28 def info return @logger.info if @logger @messages << [:info,] end |
#rebind_to(logger) ⇒ Object
24 25 26 27 |
# File 'lib/synapse/logger.rb', line 24 def rebind_to logger @logger = logger replay end |
#replay ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/synapse/logger.rb', line 36 def replay return unless @messages.is_a? Array @messages.each do || @logger.send(.first,"#{@progname}: #{.last}") end @messages=nil end |