reidmorrison / rails_semantic_logger

Rails Semantic Logger replaces the Rails default logger with Semantic Logger
https://logger.rocketjob.io/rails
Apache License 2.0
320 stars 114 forks source link

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

Open kristoph opened 2 months ago

kristoph commented 2 months ago

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,

reidmorrison commented 2 months ago

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