class ScoutApm::Logger

Attributes

log_destination[R]

Public Class Methods

new(environment_root, opts={}) click to toggle 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

debug(*args, &block) click to toggle source

Delegate calls to the underlying logger

# File lib/scout_apm/logger.rb, line 37
def debug(*args, &block); @logger.debug(*args, &block); end
debug?() click to toggle source
# File lib/scout_apm/logger.rb, line 43
def debug?; @logger.debug?; end
error(*args, &block) click to toggle source
# File lib/scout_apm/logger.rb, line 40
def error(*args, &block); @logger.error(*args, &block); end
error?() click to toggle source
# File lib/scout_apm/logger.rb, line 46
def error?; @logger.error?; end
fatal(*args, &block) click to toggle source
# File lib/scout_apm/logger.rb, line 41
def fatal(*args, &block); @logger.fatal(*args, &block); end
fatal?() click to toggle source
# File lib/scout_apm/logger.rb, line 47
def fatal?; @logger.fatal?; end
info(*args, &block) click to toggle source
# File lib/scout_apm/logger.rb, line 38
def info(*args, &block); @logger.info(*args, &block); end
info?() click to toggle source
# File lib/scout_apm/logger.rb, line 44
def info?; @logger.info?; end
log_file_path() click to toggle 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
log_level() click to toggle source
# File lib/scout_apm/logger.rb, line 53
def log_level
  @logger.level
end
log_level=(level) click to toggle source
# File lib/scout_apm/logger.rb, line 49
def log_level=(level)
  @logger.level = log_level_from_opts(level)
end
stderr?() click to toggle source
# File lib/scout_apm/logger.rb, line 65
def stderr?
  @opts[:stderr] || (@opts[:log_file_path] || "").upcase == "STDERR"
end
stdout?() click to toggle source
# File lib/scout_apm/logger.rb, line 61
def stdout?
  @opts[:stdout] || (@opts[:log_file_path] || "").upcase == "STDOUT"
end
warn(*args, &block) click to toggle source
# File lib/scout_apm/logger.rb, line 39
def warn(*args, &block); @logger.warn(*args, &block); end
warn?() click to toggle source
# File lib/scout_apm/logger.rb, line 45
def warn?; @logger.warn?; end

Private Instance Methods

build_formatter() click to toggle source
# File lib/scout_apm/logger.rb, line 92
def build_formatter
  if stdout? || stderr?
    TaggedFormatter.new
  else
    DefaultFormatter.new
  end
end
build_logger() click to toggle source
# File lib/scout_apm/logger.rb, line 71
def build_logger
  logger_class.new(@log_destination) rescue logger_class.new
end
determine_log_destination() click to toggle source
# File lib/scout_apm/logger.rb, line 114
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
log_level_from_opts(explicit=nil) click to toggle source
# File lib/scout_apm/logger.rb, line 100
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
logger_class() click to toggle source
# File lib/scout_apm/logger.rb, line 75
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
validate_path(candidate) click to toggle source

Check if this path is ok for a log file. Does it exist? Is it writable?

# File lib/scout_apm/logger.rb, line 133
def validate_path(candidate)
  return false if candidate.nil?

  directory = File.dirname(candidate)
  File.writable?(directory)
end