Module: ScoutRails::Agent::Logging

Included in:
ScoutRails::Agent
Defined in:
lib/scout_rails/agent/logging.rb

Instance Method Summary collapse

Instance Method Details

#apply_log_formatObject



23
24
25
26
27
28
29
# File 'lib/scout_rails/agent/logging.rb', line 23

def apply_log_format
  def logger.format_message(severity, timestamp, progname, msg)
    # since STDOUT isn't exclusive like the scout_rails.log file, apply a prefix.
    prefix = @logdev.dev == STDOUT ? "scout_rails " : ''
    prefix + "[#{timestamp.strftime("%m/%d/%y %H:%M:%S %z")} #{Socket.gethostname} (#{$$})] #{severity} : #{msg}\n"
  end
end

#init_loggerObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scout_rails/agent/logging.rb', line 9

def init_logger
  @log_file = "#{log_path}/scout_rails.log"
  begin 
    @logger = Logger.new(@log_file) 
    @logger.level = log_level
    apply_log_format
  rescue Exception => e
    @logger = Logger.new(STDOUT)
    apply_log_format
    @logger.error "Unable to access log file: #{e.message}"
  end
  @logger
end

#log_levelObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/scout_rails/agent/logging.rb', line 31

def log_level
  case config.settings['log_level'].downcase
    when "debug" then Logger::DEBUG
    when "info" then Logger::INFO
    when "warn" then Logger::WARN
    when "error" then Logger::ERROR
    when "fatal" then Logger::FATAL
    else Logger::INFO
  end
end

#log_pathObject



5
6
7
# File 'lib/scout_rails/agent/logging.rb', line 5

def log_path
  "#{environment.root}/log"
end