diff options
Diffstat (limited to 'activesupport/lib/active_support/testing')
-rw-r--r-- | activesupport/lib/active_support/testing/tagged_logging.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/testing/tagged_logging.rb b/activesupport/lib/active_support/testing/tagged_logging.rb new file mode 100644 index 0000000000..899467c45f --- /dev/null +++ b/activesupport/lib/active_support/testing/tagged_logging.rb @@ -0,0 +1,30 @@ +require 'active_support/concern' + +module ActiveSupport + module Testing + module TaggedLogging + extend ActiveSupport::Concern + + attr_writer :tagged_logger + + def before_setup + tagged_logger.push_tags(self.class.name, __name__) if tagged_logging? + super + end + + def after_teardown + super + tagged_logger.pop_tags(2) if tagged_logging? + end + + private + def tagged_logger + @tagged_logger ||= (defined?(Rails.logger) && Rails.logger) + end + + def tagged_logging? + tagged_logger && tagged_logger.respond_to?(:push_tags) + end + end + end +end |