Class: DataLogger::Logger
- Inherits:
-
Object
- Object
- DataLogger::Logger
- Defined in:
- lib/datalogger/logger.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
Returns the value of attribute component.
-
#sinks ⇒ Object
Returns the value of attribute sinks.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(component = 'app') ⇒ Logger
constructor
A new instance of Logger.
- #log(data, &blk) ⇒ Object
- #log_to_sinks(data) ⇒ Object
Constructor Details
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component.
3 4 5 |
# File 'lib/datalogger/logger.rb', line 3 def component @component end |
#sinks ⇒ Object
Returns the value of attribute sinks.
3 4 5 |
# File 'lib/datalogger/logger.rb', line 3 def sinks @sinks end |
Class Method Details
.component=(component) ⇒ Object
9 10 11 |
# File 'lib/datalogger/logger.rb', line 9 def self.component=(component) global_logger.component = component end |
.global_logger ⇒ Object
5 6 7 |
# File 'lib/datalogger/logger.rb', line 5 def self.global_logger @global_logger ||= new end |
.log(data, &blk) ⇒ Object
13 14 15 |
# File 'lib/datalogger/logger.rb', line 13 def self.log(data, &blk) global_logger.log(data, &blk) end |
Instance Method Details
#log(data, &blk) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datalogger/logger.rb', line 23 def log(data, &blk) if data.kind_of?(String) data = { message: data } end if blk ret = nil start = Time.now log_to_sinks(data.merge at: 'start') ret = yield log_to_sinks(data.merge at: 'finish', elapsed: (Time.now - start)) ret else log_to_sinks(data) nil end end |
#log_to_sinks(data) ⇒ Object
41 42 43 44 45 |
# File 'lib/datalogger/logger.rb', line 41 def log_to_sinks(data) self.sinks.each do |sink| sink.log(self.component, data) end end |