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

config.redirector.silence_sql_logs = true still outputting sql #8

Open
pagetribe opened this issue Jan 13, 2015 · 1 comment
Open

Comments

@pagetribe
Copy link

I have added config.redirector.silence_sql_logs = true to the config/application.rb however, I am still getting many lines of this output in my logs.

SQL (2.1ms) SELECT redirect_rules.id etc ...

@nicedawg
Copy link

The following monkey patch fixes this problem:

module Redirector
  class Middleware
    class Responder
      def with_optional_silencing(&block)
        if Redirector.silence_sql_logs
          ActiveRecord::Base.silence { yield }
        else
          yield
        end
      end
    end
  end
end

I placed the above code in config/initializers/redirector.rb, restarted my rails server, and now the silence_sql_logs setting is respected.

The key is this line of code: ActiveRecord::Base.silence { yield }. Originally, it's ActiveRecord::Base.logger.silence { yield }.

I wouldn't mind making a pull request, though I'm not sure how to properly detect if/when this monkeypatch is necessary.

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

2 participants