rails_semantic_logger
rails_semantic_logger copied to clipboard
Rails.logger doesn't support zero-arity lambdas and throws an ArgumentError
trafficstars
Environment
- Ruby Version: (3.3.2)
- Rails Version: (7.1.3.3)
- Semantic Logger Version: (4.16.1)
- Rails Semantic Logger Version: (4.17.0)
- Other Application/framework names and versions (e.g. Puma, etc.): (Puma 5.6.8)
Error Stack Trace:
Rails -- Exception: ActionView::Template::Error: wrong number of arguments (given 1, expected 0)
2024-10-19T16:49:41.074095578Z /usr/local/bundle/bundler/gems/cequel-eded31bc091f/lib/cequel/metal/request_logger.rb:34:in `block in log'
2024-10-19T16:49:41.074097255Z /usr/local/bundle/gems/semantic_logger-4.16.1/lib/semantic_logger/base.rb:344:in `log_internal'
2024-10-19T16:49:41.074098686Z /usr/local/bundle/gems/semantic_logger-4.16.1/lib/semantic_logger/base.rb:84:in `debug'
Expected Behavior
For the string returned from the lambda to get logged properly
irb(main):001> x = lambda { "log message" }
=> #<Proc:0x000076fcec1bcd20 (irb):1 (lambda)>
irb(main):002> Rails.logger.info(&x)
log message
Current Behaviour
An ArgumentError is thrown, primarily from passing the log struct to the lambda that does not accept any arguments.
irb(main):001> x = lambda { "log message" }
=> #<Proc:0x00007b46b0d80a28 (irb):1 (lambda)>
irb(main):002> Rails.logger.info(&x)
(irb):1:in `block in <top (required)>': wrong number of arguments (given 1, expected 0) (ArgumentError)
from (irb):2:in `<main>'
Please note that some of our gems do this form of logging (logging with zero-arity lambdas), and monkey patching them is not an option.