Class: Radar::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/radar/logger.rb

Overview

A lightweight logger which logs what Radar does to a single configurable location. This logger is simply meant as a way you can verify that Radar is working as intended, and not meant as a logger of every exception's data; this is the job of Reporters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ Logger

Returns a new instance of Logger.



12
13
14
15
# File 'lib/radar/logger.rb', line 12

def initialize(application)
  @application = application
  super(log_location)
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



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

def application
  @application
end

Instance Method Details

#format_message(severity, timestamp, progname, message) ⇒ Object



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

def format_message(severity, timestamp, progname, message)
  "[#{application.name}][#{severity[0,1].upcase}][#{timestamp}] -- #{message}\n"
end

#log_locationString

Returns the location of the logfile. This is configurable using Config#log_location=.

Returns:

  • (String)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/radar/logger.rb', line 25

def log_location
  location = @application.config.log_location
  location = location.is_a?(Proc) ? location.call(application) : location

  if location.is_a?(String)
    directory = File.dirname(location)
    FileUtils.mkdir_p(directory) if !File.directory?(directory)
  end

  location
end