Module: ScoutApm::Agent::Logging
- Included in:
- ScoutApm::Agent
- Defined in:
- lib/scout_apm/agent/logging.rb
Instance Method Summary collapse
- #apply_log_format ⇒ Object
- #default_log_path ⇒ Object
- #determine_log_destination ⇒ Object
- #init_logger(opts = {}) ⇒ Object
- #log_file_path ⇒ Object
- #log_level ⇒ Object
- #wants_stderr? ⇒ Boolean
- #wants_stdout? ⇒ Boolean
Instance Method Details
#apply_log_format ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/scout_apm/agent/logging.rb', line 32 def apply_log_format def logger.(severity, , 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()} #{ScoutApm::Agent.instance.environment.hostname} (#{$$})] #{severity} : #{msg}\n" end end |
#default_log_path ⇒ Object
5 6 7 |
# File 'lib/scout_apm/agent/logging.rb', line 5 def default_log_path "#{environment.root}/log" end |
#determine_log_destination ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/scout_apm/agent/logging.rb', line 51 def determine_log_destination case true when wants_stdout? then STDOUT when wants_stderr? then STDERR else "#{log_file_path}/scout_apm.log" end end |
#init_logger(opts = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scout_apm/agent/logging.rb', line 9 def init_logger(opts={}) if opts[:force] @log_file = nil @logger = nil end begin @log_file ||= determine_log_destination 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.}. Falling back to STDOUT" end @logger end |
#log_file_path ⇒ Object
67 68 69 |
# File 'lib/scout_apm/agent/logging.rb', line 67 def log_file_path config.value('log_file_path') || default_log_path end |
#log_level ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/scout_apm/agent/logging.rb', line 40 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_stderr? ⇒ Boolean
63 64 65 |
# File 'lib/scout_apm/agent/logging.rb', line 63 def wants_stderr? config.value('log_file_path').to_s.upcase == 'STDERR' end |
#wants_stdout? ⇒ Boolean
59 60 61 |
# File 'lib/scout_apm/agent/logging.rb', line 59 def wants_stdout? config.value('log_file_path').to_s.upcase == 'STDOUT' || environment.platform_integration.log_to_stdout? end |