lograge icon indicating copy to clipboard operation
lograge copied to clipboard

Fail to call Rails.logger.silent

Open belgoros opened this issue 5 years ago • 3 comments

I fail to call Rails.logger.silence in production environment. Does your Logger includes somewhere ActiveSupport::LoggerSilence module ? It throws:

NoMethodError: undefined method `silence' for #<Logger:0x007f89081dbad0>

I took a look at SilentLogger but didn't find a way to use it instead. Any idea?

  • Rails 5.2.3
  • Ruby 2.6.5

belgoros avatar Jan 21 '20 13:01 belgoros

Same here. I'm trying to use graylog by following this tutorial, which uses lograge. Everything works fine in rails c, however when I try to run server it fails with following error.

NoMethodError (undefined method 'silence_logger' for #<GELF::Logger:0x0000000007f5f170>)
  • Ruby 2.5.5
  • Rails 5.2.2
  • lograge (0.11.2)
  • gelf (3.1.0)

NormanEdance avatar Feb 10 '20 06:02 NormanEdance

Hi! If you look at the activerecord-session_store README it states:

Please note that you will need to manually include the silencer module to your custom logger if you are using a logger other than Logger and Syslog::Logger and their subclasses:

MyLogger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer

This silencer is being used to silence the logger and not leaking private information into the log, and it is required for security reason.

So in your case you will add smthing like this in /config/environments/<env>.rb

  GELF::Logger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer
  config.logger = GELF::Logger.new(...)

References: main answer, undefined method silence

NormanEdance avatar Feb 10 '20 08:02 NormanEdance

Hi! If you look at the activerecord-session_store README it states:

Please note that you will need to manually include the silencer module to your custom logger if you are using a logger other than Logger and Syslog::Logger and their subclasses:

MyLogger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer

This silencer is being used to silence the logger and not leaking private information into the log, and it is required for security reason.

So in your case you will add smthing like this in /config/environments/<env>.rb

  GELF::Logger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer
  config.logger = GELF::Logger.new(...)

References: main answer, undefined method silence

I just want to point out, if anyone comes across this issue after upgrading activerecord-session_store to 2.0, this no longer works even though their README still says what you quoted.

At some point last year (I think it was a June 2020 commit), they removed ActiveRecord::SessionStore::Extension::LoggerSilencer. There is currently an issue open here, https://github.com/rails/activerecord-session_store/issues/176, where they have offered possible solutions, but none seem to actually work yet.

I forked activerecord-session_store from the latest codebase (which fixes the CVE that sparked the need to release 2.0) and reinserted ActiveRecord::SessionStore::Extension::LoggerSilencer, so you can find that fork here if you need an immediate solution: https://github.com/egallup02360/activerecord-session_store

You can use it in your Gemfile like so

gem 'activerecord-session_store', git: 'https://github.com/egallup02360/activerecord-session_store.git', ref: 'f876987'

Hopefully they come up with a solution for this relatively soon though, I really dislike the idea of running a fork of something like this in production.

evangallup avatar Mar 13 '21 19:03 evangallup