🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

silencer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

silencer

2.0.0
Rubygems
Version published
Maintainers
1
Created
Source

Silencer

Gem Version Tests

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', require: false

Upgrading to version 2.0

Note: 1.x versions of silencer detected the presence of Rails when it was required. This made it easy to use silencer for most applications, but made assumptions on usage.

In version 2.0, you'll need to require the correct logger within your application. See the Usage documentation for more details.

Usage

Rails

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

require 'silencer/rails/logger'

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

Rack

require 'silencer/rack/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 an 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.

ConfigurationDescriptionDefault
silenceSilences matching requests regardless of request methodNone
getSilences matching GET requestsNone
headSilences matching HEAD requestsNone
postSilences matching POST requestsNone
putSilences matching PUT requestsNone
deleteSilences matching DELETE requestsNone
patchSilences matching PATCH requestsNone
traceSilences matching TRACE requestsNone
connectSilences matching CONNECT requestsNone
optionsSilences matching OPTIONS requestsNone
enable_headerEnable/disable X-SILENCE-LOGGER header supporttrue

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bugfix.
  • 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 (c) 2012 Steve Agalloco. See LICENSE for details.

FAQs

Package last updated on 24 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

OSZAR »