Class: Camayoc::Handlers::Logger

Inherits:
Object
  • Object
show all
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

IO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, options = {}) ⇒ Logger

Returns a new instance of Logger.



12
13
14
15
16
# File 'lib/camayoc/handlers/logger.rb', line 12

def initialize(logger, options={})
  self.logger = logger
  self.method = options[:method]
  self.formatter = (options[:formatter] || default_formatter)
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



10
11
12
# File 'lib/camayoc/handlers/logger.rb', line 10

def formatter
  @formatter
end

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/camayoc/handlers/logger.rb', line 10

def logger
  @logger
end

#methodObject

Returns the value of attribute method.



10
11
12
# File 'lib/camayoc/handlers/logger.rb', line 10

def method
  @method
end

Instance Method Details

#count(event) ⇒ Object



18
19
20
# File 'lib/camayoc/handlers/logger.rb', line 18

def count(event)
  write(:count,event)
end

#default_formatterObject



26
27
28
29
30
# File 'lib/camayoc/handlers/logger.rb', line 26

def default_formatter
  Proc.new do |type,event|
    "#{type} #{event.ns_stat} #{event.value} #{Time.now.utc.to_i}"
  end
end

#timing(event) ⇒ Object



22
23
24
# File 'lib/camayoc/handlers/logger.rb', line 22

def timing(event)
  write(:timing,event)
end