aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLachlan Sylvester <lachlan.sylvester@hypothetical.com.au>2015-11-18 22:53:23 +1100
committerLachlan Sylvester <lachlan.sylvester@hypothetical.com.au>2015-11-18 22:53:23 +1100
commit43c6c7787954d959347a1f90d71b11ba0cb7a8c7 (patch)
tree55c6f4070655dcf88e8c33e80f50b2be333a6470
parent6be2604aa719713c602b8a873337d328196f8f57 (diff)
downloadrails-43c6c7787954d959347a1f90d71b11ba0cb7a8c7.tar.gz
rails-43c6c7787954d959347a1f90d71b11ba0cb7a8c7.tar.bz2
rails-43c6c7787954d959347a1f90d71b11ba0cb7a8c7.zip
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.
-rw-r--r--lib/action_cable/connection/base.rb8
-rw-r--r--lib/action_cable/connection/tagged_logger_proxy.rb12
-rw-r--r--lib/action_cable/server/worker/active_record_connection_management.rb2
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb
index 6df168e4c3..b93b6a8a50 100644
--- a/lib/action_cable/connection/base.rb
+++ b/lib/action_cable/connection/base.rb
@@ -56,7 +56,7 @@ module ActionCable
def initialize(server, env)
@server, @env = server, env
- @logger = new_tagged_logger || server.logger
+ @logger = new_tagged_logger
@websocket = ActionCable::Connection::WebSocket.new(env)
@subscriptions = ActionCable::Connection::Subscriptions.new(self)
@@ -194,10 +194,8 @@ module ActionCable
# Tags are declared in the server but computed in the connection. This allows us per-connection tailored tags.
def new_tagged_logger
- if server.logger.respond_to?(:tagged)
- TaggedLoggerProxy.new server.logger,
- tags: server.config.log_tags.map { |tag| tag.respond_to?(:call) ? tag.call(request) : tag.to_s.camelize }
- end
+ TaggedLoggerProxy.new server.logger,
+ tags: server.config.log_tags.map { |tag| tag.respond_to?(:call) ? tag.call(request) : tag.to_s.camelize }
end
def started_request_message
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
diff --git a/lib/action_cable/server/worker/active_record_connection_management.rb b/lib/action_cable/server/worker/active_record_connection_management.rb
index 1ede0095f8..ecece4e270 100644
--- a/lib/action_cable/server/worker/active_record_connection_management.rb
+++ b/lib/action_cable/server/worker/active_record_connection_management.rb
@@ -12,7 +12,7 @@ module ActionCable
end
def with_database_connections
- ActiveRecord::Base.logger.tagged(*connection.logger.tags) { yield }
+ connection.logger.tag(ActiveRecord::Base.logger) { yield }
ensure
ActiveRecord::Base.clear_active_connections!
end