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

Fail to call Rails.logger.silent #309

Open
belgoros opened this issue Jan 21, 2020 · 3 comments
Open

Fail to call Rails.logger.silent #309

belgoros opened this issue Jan 21, 2020 · 3 comments

Comments

@belgoros
Copy link

belgoros commented Jan 21, 2020

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
@NormanEdance
Copy link

NormanEdance commented Feb 10, 2020

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
Copy link

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

@evangallup
Copy link

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, rails/activerecord-session_store#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.

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

3 participants