scoutapp / scout_apm_ruby

ScoutAPM Ruby Agent. Supports Rails, Sinatra, Grape, Rack, and many other frameworks

Home Page:https://scoutapm.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[ScoutApm::Logger] uninitialized constant ScoutApm::Logger::KlassHelper

josef-krabath opened this issue · comments

TL;DR:
Setting the log_class option in the scout_apm.yml config file will raise an uninitialized constant error.

# current implementation

# lib/scout_apm/logger.rb#logger_class
def logger_class
  klass = @opts.fetch(:logger_class, ::Logger)
  case klass
  when String
    result = KlassHelper.lookup(klass) # => uninitialized constant ScoutApm::Logger::KlassHelper
    ...
# fix

# lib/scout_apm/logger.rb#logger_class
def logger_class
  klass = @opts.fetch(:logger_class, ::Logger)
  case klass
  when String
    result = Utils::KlassHelper.lookup(klass)
    ...

Syslog:
I'm currently changing the logging of our rails application from a logfile-based approach to syslog.
In addition to the rails logs, I want to log the Scout logs to syslog as well.

Therefore I changed the scout_apm.yml config:

production:
  log_class: 'Syslog::Logger'
  log_file_path: 'rails' # syslog tag name
  log_stdout: true
  log_stderr: true

After patching lib/scout_apm/logger.rb#logger_class this configuration works.


Implementation:
The following snippets show how Scout is putting the pieces together.
The logger_class method returns Syslog::Logger and I'm using the log_destination variable to set the syslog tag name.

# lib/scout_apm/logger.rb#build_logger
  def build_logger
    logger_class.new(@log_destination)
  end

To use the TaggedFormatter I'm enabling log_stdout, which is kind of a hacky solution.

# lib/scout_apm/logger.rb#build_formatter
def build_formatter
  if stdout? || stderr?
    TaggedFormatter.new
  else
    DefaultFormatter.new
  end
end

I'm basically asking to change a single line.

from:

result = KlassHelper.lookup(klass)

to:

        result = Utils::KlassHelper.lookup(klass)

This change would fix the uninitialized constant ScoutApm::Logger::KlassHelper error, that I'm currently facing.
Would that be possible?

Closed via #410 - will be in our next release early next week.