Class: Radar::Reporter::LoggerReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/radar/reporter/logger_reporter.rb

Overview

A reporter which logs to a Ruby Logger-like object (any object which responds to the various log levels). This reporter is useful if you wish to integrate Radar into your already existing logging systems.

app.reporters.use :logger, :log_object => Logger.new(STDOUT)
app.reporters.use :logger, :log_object => Logger.new(STDOUT), :log_level => :warn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = nil) ⇒ LoggerReporter

Returns a new instance of LoggerReporter.



15
16
17
18
19
20
21
# File 'lib/radar/reporter/logger_reporter.rb', line 15

def initialize(opts=nil)
  (opts || {}).each do |k,v|
    send("#{k}=", v)
  end

  @log_level ||= :error
end

Instance Attribute Details

#log_levelObject

Returns the value of attribute log_level.



13
14
15
# File 'lib/radar/reporter/logger_reporter.rb', line 13

def log_level
  @log_level
end

#log_objectObject

Returns the value of attribute log_object.



12
13
14
# File 'lib/radar/reporter/logger_reporter.rb', line 12

def log_object
  @log_object
end

Instance Method Details

#report(event) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
# File 'lib/radar/reporter/logger_reporter.rb', line 23

def report(event)
  raise ArgumentError.new("#{self.class} `log_object` must respond to specified `log_level`.") if !log_object.respond_to?(log_level)

  log_object.send(log_level, event.to_json)
end