silencer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.simplecov +1 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/Guardfile +21 -0
- data/LICENSE.md +20 -0
- data/README.md +40 -0
- data/Rakefile +21 -0
- data/lib/silencer.rb +1 -0
- data/lib/silencer/logger.rb +21 -0
- data/lib/silencer/version.rb +3 -0
- data/silencer.gemspec +27 -0
- data/spec/silencer_spec.rb +35 -0
- data/spec/spec_helper.rb +9 -0
- data/tmp/.gitkeep +0 -0
- metadata +152 -0
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
SimpleCov.start
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
14
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
watch('config/routes.rb') { "spec/routing" }
|
17
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
18
|
+
# Capybara request specs
|
19
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
20
|
+
end
|
21
|
+
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Steve Agalloco
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Silencer
|
2
|
+
========
|
3
|
+
|
4
|
+
Silencer is a simple rack-middleware for Rails that can selectively disable logging on per-action basis. It's based on a [blog post](http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/) by Dennis Reimann.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Just add silencer to your Gemfile:
|
10
|
+
|
11
|
+
gem 'silencer'
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
In your production environment (presumably):
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'silencer/logger'
|
20
|
+
|
21
|
+
config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :silence => ["/noisy/action.json"]
|
22
|
+
```
|
23
|
+
|
24
|
+
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.
|
25
|
+
|
26
|
+
Note on Patches/Pull Requests
|
27
|
+
-----------------------------
|
28
|
+
|
29
|
+
* Fork the project.
|
30
|
+
* Make your feature addition or bug fix.
|
31
|
+
* Add tests for it. This is important so I don't break it in a
|
32
|
+
future version unintentionally.
|
33
|
+
* Commit, do not mess with rakefile, version, or history.
|
34
|
+
(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)
|
35
|
+
* Send me a pull request. Bonus points for topic branches.
|
36
|
+
|
37
|
+
Copyright
|
38
|
+
---------
|
39
|
+
|
40
|
+
Copyright (c) 2011 Steve Agalloco. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
task :test => :spec
|
9
|
+
|
10
|
+
namespace :doc do
|
11
|
+
require 'yard'
|
12
|
+
YARD::Rake::YardocTask.new do |task|
|
13
|
+
task.files = ['lib/**/*.rb']
|
14
|
+
task.options = [
|
15
|
+
'--protected',
|
16
|
+
'--output-dir', 'doc/yard',
|
17
|
+
'--markup', 'markdown',
|
18
|
+
'--readme', 'README.md'
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
data/lib/silencer.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'silencer/logger'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/rack/logger'
|
2
|
+
|
3
|
+
module Silencer
|
4
|
+
class Logger < Rails::Rack::Logger
|
5
|
+
def initialize(app, opts = {})
|
6
|
+
@app = app
|
7
|
+
@opts = opts
|
8
|
+
@opts[:silence] ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env['X-SILENCE-LOGGER'] || @opts[:silence].include?(env['PATH_INFO'])
|
13
|
+
Rails.logger.silence do
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
super(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/silencer.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/silencer/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "silencer"
|
6
|
+
gem.version = Silencer::VERSION
|
7
|
+
gem.authors = ["Steve Agalloco"]
|
8
|
+
gem.email = ["steve.agalloco@gmail.com"]
|
9
|
+
gem.homepage = "http://github.com/spagalloco/silencer"
|
10
|
+
gem.description = 'Selectively quiet your Rails logger on a per-action basis'
|
11
|
+
gem.summary = gem.description
|
12
|
+
|
13
|
+
gem.add_development_dependency('rake', '~> 0.9')
|
14
|
+
gem.add_development_dependency('rspec', '~> 2.6')
|
15
|
+
gem.add_development_dependency('yard', '~> 0.7')
|
16
|
+
gem.add_development_dependency('rdiscount', '~> 1.6')
|
17
|
+
gem.add_development_dependency('simplecov', '~> 0.5')
|
18
|
+
gem.add_development_dependency('guard', '~> 0.8')
|
19
|
+
gem.add_development_dependency('guard-rspec', '~> 0.5')
|
20
|
+
|
21
|
+
gem.add_dependency 'railties', '~> 3'
|
22
|
+
|
23
|
+
gem.files = `git ls-files`.split("\n")
|
24
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
gem.require_paths = ["lib"]
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Silencer::Logger do
|
4
|
+
before(:each) do
|
5
|
+
@app = lambda { |env| [200, {}, ''] }
|
6
|
+
|
7
|
+
Rails.logger = ActiveSupport::BufferedLogger.new('tmp/test.log')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'allows log writing when not implemented' do
|
11
|
+
Rails.logger.should_not_receive(:silence)
|
12
|
+
Rails.logger.should_receive(:info).at_least(:once)
|
13
|
+
|
14
|
+
Silencer::Logger.new(@app).call(Rack::MockRequest.env_for("/"))
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'quiets the log when configured with a silenced path' do
|
18
|
+
Rails.logger.should_receive(:silence)
|
19
|
+
Rails.logger.should_not_receive(:info)
|
20
|
+
|
21
|
+
Silencer::Logger.new(@app, :silence => ['/']).call(Rack::MockRequest.env_for("/"))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'quiets the log when passed a custom header "X-SILENCE-LOGGER"' do
|
25
|
+
Rails.logger.should_receive(:silence)
|
26
|
+
Rails.logger.should_not_receive(:info)
|
27
|
+
|
28
|
+
Silencer::Logger.new(@app).call(Rack::MockRequest.env_for("/", 'X-SILENCE-LOGGER' => 'true'))
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'does not tamper with the response' do
|
32
|
+
response = Silencer::Logger.new(@app).call(Rack::MockRequest.env_for("/", 'X-SILENCE-LOGGER' => 'true'))
|
33
|
+
response[0].should eq(200)
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tmp/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: silencer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Agalloco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2153098740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153098740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2153098240 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.6'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153098240
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
requirement: &2153097780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.7'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153097780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rdiscount
|
49
|
+
requirement: &2153097320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153097320
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &2153127820 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0.5'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2153127820
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: &2153127360 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.8'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2153127360
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-rspec
|
82
|
+
requirement: &2153126900 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.5'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2153126900
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: railties
|
93
|
+
requirement: &2153126440 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '3'
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2153126440
|
102
|
+
description: Selectively quiet your Rails logger on a per-action basis
|
103
|
+
email:
|
104
|
+
- steve.agalloco@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- .gemtest
|
110
|
+
- .gitignore
|
111
|
+
- .rspec
|
112
|
+
- .simplecov
|
113
|
+
- .yardopts
|
114
|
+
- Gemfile
|
115
|
+
- Guardfile
|
116
|
+
- LICENSE.md
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- lib/silencer.rb
|
120
|
+
- lib/silencer/logger.rb
|
121
|
+
- lib/silencer/version.rb
|
122
|
+
- silencer.gemspec
|
123
|
+
- spec/silencer_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- tmp/.gitkeep
|
126
|
+
homepage: http://github.com/spagalloco/silencer
|
127
|
+
licenses: []
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.6
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Selectively quiet your Rails logger on a per-action basis
|
150
|
+
test_files:
|
151
|
+
- spec/silencer_spec.rb
|
152
|
+
- spec/spec_helper.rb
|