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 e41285f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 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,21 @@ 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. With that being said, we shouldn't impact the original
# applications intended behavior and let the user know we don't support it and no-op.
def method_missing(name, *_args)
return unless defined?(::Rails)

::Rails.logger.warn("Method #{name} called on ScoutApm::Logging::Loggers::FileLogger, but it is not defined.")
end

# More impactful for the broadcast logger.
def respond_to_missing?(name, *_args)
super
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.is_a?(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 e41285f

Please sign in to comment.