• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 13 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily suppress the Rails logger

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.

Configuration Description Default
silence Silences matching requests regardless of request method None
get Silences matching GET requests None
head Silences matching HEAD requests None
post Silences matching POST requests None
put Silences matching PUT requests None
delete Silences matching DELETE requests None
patch Silences matching PATCH requests None
trace Silences matching TRACE requests None
connect Silences matching CONNECT requests None
options Silences matching OPTIONS requests None
enable_header Enable/disable X-SILENCE-LOGGER header support true

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

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

More Repositories

1

capistrano-local-precompile

Fast asset compilation and deployment for your Rails app
Ruby
199
star
2

instapaper

Ruby Client for Instapaper's Full API
Ruby
95
star
3

awesome-dropwizard

Shell
92
star
4

bower

Bower integration for your ruby/rails apps.
Ruby
47
star
5

airbrake-api

Airbrake API Ruby Client
Ruby
44
star
6

tophat

TopHat is a set of view helpers to keep your Rails layouts and views DRY.
Ruby
29
star
7

alfred-vpn

Alfred 3 workflow to connect/disconnect from VPNs
JavaScript
23
star
8

bluepill-examples

Example usages of bluepill I've found on the web
Ruby
18
star
9

current-cli

See what language versions are configured in your current environment
JavaScript
16
star
10

watch-later-api

YouTube Watch Later playlist Workflow integration
Ruby
16
star
11

omniauth-dropbox

Dropbox Strategy for OmniAuth 1.0
Ruby
15
star
12

pow_proxy

A simple rack-based proxy that allows you to run your node apps through Pow.
Ruby
12
star
13

alfred-ipaddress

Alfred 3 workflow to display internal/external IP addresses
JavaScript
10
star
14

awesome-ratpack

Shell
10
star
15

domainr

Ruby wrapper for the Domainr API
Ruby
10
star
16

omniauth-instapaper

OmniAuth 1.0 Strategy for Instapaper Full API
Ruby
9
star
17

rvmify

get up and running quickly with rvm, gemsets and bundler
Ruby
7
star
18

mongo_mapper_generators

Generators for use with the MongoMapper rubygem.
Ruby
6
star
19

nativize.css

Stylesheet defaults to help electron apps feel native
CSS
6
star
20

css-architectures

5
star
21

jsonwhois

WHOIS over HTTP, served as JSON
Ruby
5
star
22

yql-query

A simple query builder for YQL
Ruby
5
star
23

arr-force

Faraday Middleware to ensure certain keys are converted to arrays
Ruby
4
star
24

itunes-charts

A simple rubygem to retrieve itms charts from apple.com
Ruby
4
star
25

omniauth-netflix

Netflix Strategy for OmniAuth 1.0
Ruby
4
star
26

em-logger

experimental logger class for EventMachine
Ruby
4
star
27

rack-lettering

Rack Middleware for inserting Lettering.js style syntax into a response body
Ruby
4
star
28

scar

Soundcloud artwork downloader
Go
3
star
29

mog

Mog API
Ruby
3
star
30

eager

Ruby
2
star
31

install-scripts

Bash scripts for commonly installed items
Ruby
2
star
32

old-dotfiles

Everyone has them, these are mine
Shell
2
star
33

go-opengraph-server

Go
2
star
34

go-oembed-server

Go
2
star
35

gstock

A simple API wrapper for google finance stock quotes.
Ruby
2
star
36

jekyll-atom

atom feeds for jekyll
1
star
37

rails-template

My preferred default rails stack
Ruby
1
star
38

.js

My .js files
JavaScript
1
star
39

negatives

Ruby
1
star
40

viewqueue

Experimenting with node and phantom.js
JavaScript
1
star
41

roe

A simple Ruby oEmbed client
Ruby
1
star
42

sshpeek

Simple command-line tool for displaying ssh config info
Ruby
1
star
43

websockets-example

JavaScript
1
star