Merge pull request #125 from lsylvester/handle-custom-loggers
Handle cases where logger is not a tagged logger.
This commit is contained in:
commit
cf4d9aa992
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue