Skip to content
Easily suppress the Rails logger
Branch: master
Clone or download
Latest commit 538df8f Dec 22, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Fix linter warnings Dec 22, 2018
spec Fix rack logger tests Dec 22, 2018
.gemtest initial commit Oct 13, 2011
.gitignore initial commit Oct 13, 2011
.rspec fix the spec config for rspec 2 May 5, 2015
.rubocop.yml Fix rubocop rule definitions Dec 20, 2018
.travis.yml Update test matrix, drop support for Rails and Ruby EOL versions Dec 20, 2018
.yardopts initial commit Oct 13, 2011
CHANGELOG.md added changelog Mar 21, 2017
Gemfile Fix linter warnings Dec 22, 2018
LICENSE.md readme and license updates Jan 25, 2012
README.md Add config.log_tags to the Rails setup Dec 20, 2018
Rakefile lint with rubocop Apr 5, 2016
silencer.gemspec

README.md

Silencer

Gem Version Build Status Dependency Status

Silencer is a simple rack-middleware for Rails that can selectively disable logging on per-action basis. It's based on a blog post by Dennis Reimann.

Note: Silencer is only threadsafe in Rails version 4.2.6 and later.

Installation

Just add silencer to your Gemfile:

gem 'silencer'

Usage

Rails

Create an initializer (like config/initializers/silencer.rb) with the contents:

require 'silencer/logger'

Rails.application.configure do
  config.middleware.swap(
    Rails::Rack::Logger, 
    Silencer::Logger, 
    config.log_tags,
    silence: ["/noisy/action.json"]
  )
end

Rack

require 'silencer/logger'

use Silencer::Logger, :silence => ["/noisy/action.json"]

Configuration

Or if you'd prefer, you can pass it regular expressions:

config.middleware.swap(
  Rails::Rack::Logger, 
  Silencer::Logger, 
  config.log_tags, 
  silence: [%r{^/assets/}]
)

Or you can silence specific request methods only:

config.middleware.swap(
  Rails::Rack::Logger, 
  Silencer::Logger, 
  config.log_tags, 
  get: [%r{^/assets/}], 
  post: [%r{^/some_path}]
)

Silencer's logger will serve as a drop-in replacement for Rails' default logger. It will not suppress any logging by default, simply pass it an array of urls via the options hash. You can also send it a 'X-SILENCE-LOGGER' header (with any value) with your request and that will also produce the same behavior.

All options

Silencer supports the following configuration options.

:silence - Silences matching requests regardless of request method
:get     - Silences matching GET requests
:head    - Silences matching HEAD requests
:post    - Silences matching POST requests
:put     - Silences matching PUT requests
:delete  - Silences matching DELETE requests
:patch   - Silences matching PATCH requests
:trace   - Silences matching TRACE requests
:connect - Silences matching CONNECT requests
:options - Silences matching OPTIONS requests

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2012 Steve Agalloco. See LICENSE for details.

You can’t perform that action at this time.