rails_semantic_logger icon indicating copy to clipboard operation
rails_semantic_logger copied to clipboard

SemanticLogger is incompatible with ActionCable::Connection because of ActionCable::Connection::TaggedLoggerProxy

Open kristoph opened this issue 1 year ago • 2 comments
trafficstars

Attempting to include SemanticLogger::Loggable in a class derived from ActionCable::Connection::Base will mean connect on the base class will never be called.

Because ActionCable::Connection implements its own logger, the TaggedLoggerProxy, any attempt to call a logger method with more than the message parameter will fail with "ArgumentError(wrong number of arguments (given 2, expected 0..1))" because such methods do not exist on TaggedLoggerProxy.

This is even true when you manually construct a logger because ActionCable::Connection::Base wraps the logger.

I am using Ruby 3.2 with actioncable-7.1.3.4,

kristoph avatar Jun 25 '24 03:06 kristoph

It is unlikely just adding "SemanticLogger::Loggable in a class derived from ActionCable::Connection::Base" would work for Rails. It usually requires far more extensive patching.

Start here to see the patches for the other Rails frameworks and the community contributed fix that may help, to see what changes would be required to support Rails 7.1 Action Cable: https://github.com/reidmorrison/rails_semantic_logger/blob/6e1291f49c74f7241dbc9e92e28fbd60f8a1f37e/lib/rails_semantic_logger/engine.rb#L87

A Tagged proxy patch: https://github.com/reidmorrison/rails_semantic_logger/blob/0a43d8d3ad6cf6a41de796713d89b4d46116d82a/lib/rails_semantic_logger/extensions/action_cable/tagged_logger_proxy.rb#L5

At some point it will also need its own log subscriber to break down the text messages into log events. Below is an example of how this is being done for Action Controller: https://github.com/reidmorrison/rails_semantic_logger/blob/9e97777c04898bae4503daefa35168f2a16e96f3/lib/rails_semantic_logger/action_controller/log_subscriber.rb#L3

reidmorrison avatar Jul 05 '24 20:07 reidmorrison

Is there any way to work around this for ActionCable? Currently this is breaking ActionCable from being able to establish connections in my app

tcannonfodder avatar Nov 18 '24 05:11 tcannonfodder