Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails.logger doesn't support zero-arity lambdas and throws an ArgumentError #243

Open
laythra opened this issue Oct 19, 2024 · 0 comments
Open

Comments

@laythra
Copy link

laythra commented Oct 19, 2024

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.

@laythra laythra changed the title Rails.logger doesn't support zero-arity lamdas and throws an ArgumentError Rails.logger doesn't support zero-arity lambdas and throws an ArgumentError Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant