From 3cde2ff6b3c87bcf80347bab5046676a3dcf26ff Mon Sep 17 00:00:00 2001 From: Jack Rothrock Date: Tue, 27 Aug 2024 11:04:41 -0600 Subject: [PATCH] Treat proxy logger as original logger class --- lib/scout_apm/logging/loggers/logger.rb | 7 +++++++ lib/scout_apm/logging/loggers/proxy.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/scout_apm/logging/loggers/logger.rb b/lib/scout_apm/logging/loggers/logger.rb index b2e5819..7e29f56 100644 --- a/lib/scout_apm/logging/loggers/logger.rb +++ b/lib/scout_apm/logging/loggers/logger.rb @@ -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. diff --git a/lib/scout_apm/logging/loggers/proxy.rb b/lib/scout_apm/logging/loggers/proxy.rb index 7d2c9e8..81657a2 100644 --- a/lib/scout_apm/logging/loggers/proxy.rb +++ b/lib/scout_apm/logging/loggers/proxy.rb @@ -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.