From 43c6c7787954d959347a1f90d71b11ba0cb7a8c7 Mon Sep 17 00:00:00 2001 From: Lachlan Sylvester Date: Wed, 18 Nov 2015 22:53:23 +1100 Subject: Handle cases where logger is not a tagged logger. Previously, a TaggedLoggerProxy was only created if the logger responded to :tagged, but was still used as if it was a TaggedLoggerProxy elsewhere in the code, causing undefined method errors. This moved the check for tagging abilities inside the TaggedLoggerProxy so the code can always tread the logger like a tagged logger, and if it is not a tagged logger the tags will just be ignored. This prevents needing to check if the logger is tagged every time we use it. --- lib/action_cable/connection/tagged_logger_proxy.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/action_cable/connection/tagged_logger_proxy.rb') diff --git a/lib/action_cable/connection/tagged_logger_proxy.rb b/lib/action_cable/connection/tagged_logger_proxy.rb index 34063c1d42..e5319087fb 100644 --- a/lib/action_cable/connection/tagged_logger_proxy.rb +++ b/lib/action_cable/connection/tagged_logger_proxy.rb @@ -16,6 +16,15 @@ module ActionCable @tags = @tags.uniq end + def tag(logger) + if logger.respond_to?(:tagged) + current_tags = tags - logger.formatter.current_tags + logger.tagged(*current_tags) { yield } + else + yield + end + end + %i( debug info warn error fatal unknown ).each do |severity| define_method(severity) do |message| log severity, message @@ -24,8 +33,7 @@ module ActionCable protected def log(type, message) - current_tags = tags - @logger.formatter.current_tags - @logger.tagged(*current_tags) { @logger.send type, message } + tag(@logger) { @logger.send type, message } end end end -- cgit v1.2.3