Skip to content

Commit

Permalink
Treat proxy logger as original logger class
Browse files Browse the repository at this point in the history
  • Loading branch information
jrothrock committed Aug 27, 2024
1 parent eab30be commit 3cde2ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/scout_apm/logging/loggers/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ module Loggers
# The actual instance of the logger.
class FileLogger < ::Logger
include ::ActiveSupport::LoggerSilence if const_defined?('::ActiveSupport::LoggerSilence')

# Other loggers may be extended with additional methods that have not been applied to this file logger.
# Most likely, these methods will still utilize the exiting logging methods to write to the IO device,
# however, if this is not the case we may miss logs.
def method_missing(name, *args, &block)
::Rails.logger.warn("Method #{name} called on ScoutApm::Logging::Loggers::FileLogger, but it is not defined.") if defined?(::Rails)
end
end

# The newly created logger which we can configure, and will log to a filepath.
Expand Down
16 changes: 16 additions & 0 deletions lib/scout_apm/logging/loggers/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ def remove_scout_loggers(logger)
@loggers
end

def is_a?(klass)
@loggers.first.is_a?(klass)
end

def instance_of?(klass)
@loggers.first.instance_of?(klass)
end

def kind_of?(klass)
@loggers.first.kind_of?(klass)
end

def class
@loggers.first.class
end

def method_missing(name, *args, &block)
# Some libraries will do stuff like Library.logger.formatter = Rails.logger.formatter
# As such, we should return the first logger's (the original logger) return value.
Expand Down

0 comments on commit 3cde2ff

Please sign in to comment.