Class: Camayoc::Handlers::Logger
- Inherits:
-
Object
- Object
- Camayoc::Handlers::Logger
- Defined in:
- lib/camayoc/handlers/logger.rb
Overview
Write stats to a logger. Specify the method to call on the logger instance with :method (usually something like :info). If not :method is specified :debug will be called on the logger. You can control the format of the message passed to the logger method using the :formatter Proc.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#method ⇒ Object
Returns the value of attribute method.
Instance Method Summary collapse
- #default_formatter ⇒ Object
- #event(ev) ⇒ Object
-
#initialize(logger, options = {}, &block) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(logger, options = {}, &block) ⇒ Logger
Returns a new instance of Logger.
12 13 14 15 16 17 18 19 20 |
# File 'lib/camayoc/handlers/logger.rb', line 12 def initialize(logger, ={}, &block) self.logger = logger self.method = [:method] if block_given? self.formatter = block else self.formatter = ([:formatter] || default_formatter) end end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
10 11 12 |
# File 'lib/camayoc/handlers/logger.rb', line 10 def formatter @formatter end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/camayoc/handlers/logger.rb', line 10 def logger @logger end |
#method ⇒ Object
Returns the value of attribute method.
10 11 12 |
# File 'lib/camayoc/handlers/logger.rb', line 10 def method @method end |
Instance Method Details
#default_formatter ⇒ Object
31 32 33 34 35 |
# File 'lib/camayoc/handlers/logger.rb', line 31 def default_formatter Proc.new do |event| "#{event.type} #{event.ns_stat} #{event.value} #{Time.now.utc.to_i}" end end |
#event(ev) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/camayoc/handlers/logger.rb', line 22 def event(ev) msg = formatter.call(ev) if @method @logger.send(@method,msg) else @logger.debug(msg) end end |