Class: Radar::Reporter::IoReporter

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

Overview

A reporter which simply dumps the event JSON out to some IO object. If you're outputting to a file, you should look into FileReporter instead, which will automatically create unique filenames per exception.

Some uses for this reporter:

  • Output to stderr, since a process's stderr may be redirected to a log file already.
  • Output to stdout, just for testing.
  • Output to some network IO stream to talk to a server across a network.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = nil) ⇒ IoReporter

Returns a new instance of IoReporter.



19
20
21
22
23
# File 'lib/radar/reporter/io_reporter.rb', line 19

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

Instance Attribute Details

#io_objectObject

Returns the value of attribute io_object.



17
18
19
# File 'lib/radar/reporter/io_reporter.rb', line 17

def io_object
  @io_object
end

Instance Method Details

#report(event) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/radar/reporter/io_reporter.rb', line 25

def report(event)
  return if !io_object
  raise ArgumentError.new("IoReporter `io_object` must be an IO object.") if !io_object.is_a?(IO)

  # Straight push the object to the object and flush immediately
  io_object.puts(event.to_json)
  io_object.flush
end