dwbutler / logstash-logger

Ruby logger that writes logstash events
MIT License
456 stars 118 forks source link

undefined method `reset' for #<ActiveSupport::Logger #151

Open entropywtf opened 5 years ago

entropywtf commented 5 years ago

Hi, Following the documentation, I put Rails.logger.reset into config/puma.rb

On server start though, I get an error:

undefined methodreset' for # 6: from /Users/marina/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:137:in fork' (NoMethodError ( 5: from /Users/marina/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:137:inblock (2 levels) in spawn_workers' NoMethodErrorNoMethodError)`

Thanks and sorry if I'm missing something obvious here. KR

entropywtf commented 5 years ago

After looking closer and going through merged PRs I found out that reset method was exposed and it is actually a feature, BUT:

If you run into this error, you still have Rails.logger not set to Logstash. If Logstash logging is conditional in your application, you better put Rails.logger.reset under a condition likeif respond_to?(:reset) or if ENV['LOGSTASH_ENABLED'] like I did in my project.

I'd suggest to put this advice into a README.

Thanks!

bv-ritesh commented 3 years ago

In case of multilogger, the instance does not respond to reset method.

logger.loggers.each { |_logger|
 _logger.respond_to?(:reset)
}

This will work