Module: ScoutApm::Agent::Logging

Included in:
ScoutApm::Agent
Defined in:
lib/scout_apm/agent/logging.rb

Instance Method Summary collapse

Instance Method Details

#apply_log_formatObject



28
29
30
31
32
33
34
# File 'lib/scout_apm/agent/logging.rb', line 28

def apply_log_format
  def logger.format_message(severity, timestamp, progname, msg)
    # since STDOUT isn't exclusive like the scout_apm.log file, apply a prefix.
    prefix = @logdev.dev == STDOUT ? "[Scout] " : ''
    prefix + "[#{Utils::Time.to_s(timestamp)} #{ScoutApm::Agent.instance.environment.hostname} (#{$$})] #{severity} : #{msg}\n"
  end
end

#default_log_pathObject



6
7
8
# File 'lib/scout_apm/agent/logging.rb', line 6

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

#init_loggerObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scout_apm/agent/logging.rb', line 10

def init_logger
  begin
    @log_file = wants_stdout? ? STDOUT : "#{log_file_path}/scout_apm.log"
  rescue => e
  end

  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 open log file for writing: #{e.message}. Falling back to STDOUT"
  end
  @logger
end

#log_file_pathObject



47
48
49
# File 'lib/scout_apm/agent/logging.rb', line 47

def log_file_path
  config.value('log_file_path') || default_log_path
end

#log_levelObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/scout_apm/agent/logging.rb', line 36

def log_level
  case config.value('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

#wants_stdout?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/scout_apm/agent/logging.rb', line 51

def wants_stdout?
  config.value('log_file_path').to_s.upcase == 'STDOUT' || environment.heroku?
end