Class: Radar::Reporter::FileReporter
- Inherits:
-
Object
- Object
- Radar::Reporter::FileReporter
- Defined in:
- lib/radar/reporter/file_reporter.rb
Overview
Reports exceptions by dumping the JSON data out to a file on the local filesystem. The reporter is configurable:
Instance Attribute Summary collapse
-
#output_directory(event = nil) ⇒ Object
Returns the currently configured output directory.
Instance Method Summary collapse
-
#initialize ⇒ FileReporter
constructor
A new instance of FileReporter.
- #report(event) ⇒ Object
Constructor Details
#initialize ⇒ FileReporter
Returns a new instance of FileReporter.
13 14 15 |
# File 'lib/radar/reporter/file_reporter.rb', line 13 def initialize @output_directory = lambda { |event| "~/.radar/errors/#{event.application.name}" } end |
Instance Attribute Details
#output_directory(event = nil) ⇒ Object
Returns the currently configured output directory. If ‘event` is given as a parameter and the currently set directory is a lambda, then the lambda will be evaluated then returned. If no event is given, the lambda is returned as-is.
31 32 33 |
# File 'lib/radar/reporter/file_reporter.rb', line 31 def output_directory @output_directory end |
Instance Method Details
#report(event) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/radar/reporter/file_reporter.rb', line 17 def report(event) output_file = File.join(File.(output_directory(event)), "#{event.occurred_at.to_i}-#{event.uniqueness_hash}.txt") # Attempt to make the directory if it doesn't exist FileUtils.mkdir_p File.dirname(output_file) # Write out the JSON to the output file File.open(output_file, 'w') { |f| f.write(event.to_json) } end |