class ScoutApm::Logger
Attributes
Public Class Methods
Source
# File lib/scout_apm/logger.rb, line 26 def initialize(environment_root, opts={}) @opts = opts @environment_root = environment_root @log_destination = determine_log_destination @logger = build_logger self.log_level = log_level_from_opts @logger.formatter = build_formatter end
Public Instance Methods
Source
# File lib/scout_apm/logger.rb, line 37 def debug(*args, &block); @logger.debug(*args, &block); end
Delegate calls to the underlying logger
Source
# File lib/scout_apm/logger.rb, line 40 def error(*args, &block); @logger.error(*args, &block); end
Source
# File lib/scout_apm/logger.rb, line 41 def fatal(*args, &block); @logger.fatal(*args, &block); end
Source
# File lib/scout_apm/logger.rb, line 38 def info(*args, &block); @logger.info(*args, &block); end
Source
# File lib/scout_apm/logger.rb, line 57 def log_file_path @opts.fetch(:log_file_path, "#{@environment_root}/log") || "#{@environment_root}/log" end
Source
# File lib/scout_apm/logger.rb, line 49 def log_level=(level) @logger.level = log_level_from_opts(level) end
Source
# File lib/scout_apm/logger.rb, line 65 def stderr? @opts[:stderr] || (@opts[:log_file_path] || "").upcase == "STDERR" end
Source
# File lib/scout_apm/logger.rb, line 61 def stdout? @opts[:stdout] || (@opts[:log_file_path] || "").upcase == "STDOUT" end
Source
# File lib/scout_apm/logger.rb, line 39 def warn(*args, &block); @logger.warn(*args, &block); end
Private Instance Methods
Source
# File lib/scout_apm/logger.rb, line 96 def build_formatter if stdout? || stderr? TaggedFormatter.new else DefaultFormatter.new end end
Source
# File lib/scout_apm/logger.rb, line 71 def build_logger logger_class.new(@log_destination) rescue => e logger = ::Logger.new(STDERR) logger.error("Error while building ScoutApm logger: #{e.message}. Falling back to STDERR") logger end
Source
# File lib/scout_apm/logger.rb, line 118 def determine_log_destination case true when stdout? STDOUT when stderr? STDERR when validate_path(@opts[:log_file]) @opts[:log_file] when validate_path("#{log_file_path}/scout_apm.log") "#{log_file_path}/scout_apm.log" else # Safe fallback STDOUT end end
Source
# File lib/scout_apm/logger.rb, line 104 def log_level_from_opts(explicit=nil) candidate = explicit || (@opts[:log_level] || "").downcase case candidate 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 when ::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN, ::Logger::ERROR, ::Logger::FATAL then candidate else ::Logger::INFO end end
Source
# File lib/scout_apm/logger.rb, line 79 def logger_class klass = @opts.fetch(:logger_class, ::Logger) case klass when String result = Utils::KlassHelper.lookup(klass) if result == :missing_class ::Logger else result end when Class klass else ::Logger end end
Source
# File lib/scout_apm/logger.rb, line 137 def validate_path(candidate) return false if candidate.nil? directory = File.dirname(candidate) File.writable?(directory) end
Check if this path is ok for a log file. Does it exist? Is it writable?