silencer 1.0.0.rc3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -12
- data/Rakefile +10 -15
- data/lib/silencer/environment.rb +3 -5
- data/lib/silencer/hush.rb +10 -3
- data/lib/silencer/logger.rb +9 -6
- data/lib/silencer/methods.rb +12 -0
- data/lib/silencer/rack/logger.rb +6 -14
- data/lib/silencer/rails/logger.rb +49 -25
- data/lib/silencer/util.rb +0 -2
- data/lib/silencer/version.rb +1 -1
- data/silencer.gemspec +1 -1
- data/spec/silencer/rack/logger_spec.rb +17 -17
- data/spec/silencer/rails/logger_spec.rb +57 -64
- data/spec/spec_helper.rb +5 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2f6e12917e629307fa4e989b58e40e582239b48
|
4
|
+
data.tar.gz: 00d6fdf3db1107a3eeab0774d6d19e229d0365df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50c6487b88a6fa6fff7a5c621a5207d75a7bbb32b891cabdfbd08cb343f57eb9a2df1dd3a2ed9794e4c1f1368e1a6aeddff1d953b8efee944cfbdb3b60dfd096
|
7
|
+
data.tar.gz: 1025cf5f7748607427929508c1f1f615231f1847e55ae0209213b389cd574a88d4cd27e3b97794337d6f86afc379da563df4b621a6b81c4f8afadb025899529c
|
data/README.md
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
# Silencer
|
1
|
+
# Silencer
|
2
2
|
|
3
|
-
|
4
|
-
[
|
3
|
+
|
4
|
+
[][gem]
|
5
|
+
[][travis]
|
6
|
+
[][gemnasium]
|
7
|
+
|
8
|
+
[gem]: https://rubygems.org/gems/silencer
|
9
|
+
[travis]: https://travis-ci.org/stve/silencer
|
10
|
+
[gemnasium]: https://gemnasium.com/stve/silencer
|
5
11
|
|
6
12
|
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.
|
7
13
|
|
8
|
-
__Note__: Silencer is
|
14
|
+
__Note__: Silencer is only threadsafe in Rails version 4.2.6 and later.
|
9
15
|
|
10
16
|
## Installation
|
11
17
|
|
@@ -15,22 +21,39 @@ Just add silencer to your Gemfile:
|
|
15
21
|
|
16
22
|
## Usage
|
17
23
|
|
18
|
-
|
24
|
+
### Rails
|
19
25
|
|
26
|
+
Create an initializer (like `config/initializers/silencer.rb`) with the contents:
|
20
27
|
|
21
|
-
|
28
|
+
```ruby
|
29
|
+
require 'silencer/logger'
|
22
30
|
|
23
|
-
|
31
|
+
Rails.application.configure do
|
32
|
+
config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :silence => ["/noisy/action.json"]
|
33
|
+
end
|
34
|
+
```
|
24
35
|
|
25
|
-
|
36
|
+
### Rack
|
26
37
|
|
38
|
+
```ruby
|
39
|
+
require 'silencer/logger'
|
27
40
|
|
28
|
-
|
41
|
+
use Silencer::Logger, :silence => ["/noisy/action.json"]
|
42
|
+
```
|
29
43
|
|
30
|
-
|
44
|
+
## Configuration
|
31
45
|
|
46
|
+
Or if you'd prefer, you can pass it regular expressions:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :silence => [%r{^/assets/}]
|
50
|
+
```
|
51
|
+
|
52
|
+
Or you can silence specific request methods only:
|
32
53
|
|
33
|
-
|
54
|
+
```ruby
|
55
|
+
config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :get => [%r{^/assets/}], :post => [%r{^/some_path}]
|
56
|
+
```
|
34
57
|
|
35
58
|
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.
|
36
59
|
|
@@ -53,7 +76,9 @@ Silencer supports the following configuration options.
|
|
53
76
|
|
54
77
|
Rails 2.3.x introduced a tagged logging feature. If you are using tagged logging with Rails 2.3 you can also pass taggers via the middleware:
|
55
78
|
|
56
|
-
|
79
|
+
```ruby
|
80
|
+
config.middleware.swap Rails::Rack::Logger, Silencer::Logger, config.log_tags, :silence => [%r{^/assets/}]
|
81
|
+
```
|
57
82
|
|
58
83
|
## Note on Patches/Pull Requests
|
59
84
|
|
data/Rakefile
CHANGED
@@ -1,21 +1,16 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
7
|
task :default => :spec
|
8
|
-
task :
|
8
|
+
task test: :spec
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
'--markup', 'markdown',
|
18
|
-
'--readme', 'README.md'
|
19
|
-
]
|
20
|
-
end
|
21
|
-
end
|
10
|
+
require 'rubocop/rake_task'
|
11
|
+
RuboCop::RakeTask.new
|
12
|
+
|
13
|
+
require 'yard'
|
14
|
+
YARD::Rake::YardocTask.new
|
15
|
+
|
16
|
+
task default: [:spec, :rubocop]
|
data/lib/silencer/environment.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Silencer
|
2
2
|
module Environment
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
RAILS_4 = %r{^4}
|
3
|
+
RAILS_2_3 = /^2.3/
|
4
|
+
RAILS_3_2 = /^3.2/
|
5
|
+
RAILS_4 = /^4/
|
7
6
|
|
8
7
|
def rails?
|
9
8
|
defined?(::Rails)
|
@@ -32,6 +31,5 @@ module Silencer
|
|
32
31
|
|
33
32
|
module_function :rails?, :rails2?, :rails_version, :rails3_2?
|
34
33
|
module_function :rails4?, :tagged_logger?
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
data/lib/silencer/hush.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Silencer
|
2
2
|
module Hush
|
3
|
-
|
4
3
|
private
|
5
4
|
|
6
5
|
def silence_request?(env)
|
@@ -12,8 +11,16 @@ module Silencer
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def silent_path?(env)
|
15
|
-
(@routes[env['REQUEST_METHOD']] || @silence).any?
|
14
|
+
(@routes[env['REQUEST_METHOD']] || @silence).any? do |rule|
|
15
|
+
case rule
|
16
|
+
when String, Integer
|
17
|
+
rule.to_s == env['PATH_INFO']
|
18
|
+
when Regexp
|
19
|
+
rule =~ env['PATH_INFO']
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
16
24
|
end
|
17
|
-
|
18
25
|
end
|
19
26
|
end
|
data/lib/silencer/logger.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
require 'silencer/environment'
|
2
1
|
require 'silencer/rack/logger'
|
3
|
-
require 'silencer/
|
2
|
+
require 'silencer/environment'
|
4
3
|
|
5
4
|
module Silencer
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# rubocop:disable Style/ConstantName
|
6
|
+
Logger = begin
|
7
|
+
if Silencer::Environment.rails?
|
8
|
+
require 'silencer/rails/logger'
|
9
|
+
Silencer::Rails::Logger
|
10
|
+
else
|
11
|
+
Silencer::Rack::Logger
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Silencer
|
2
|
+
module Methods
|
3
|
+
METHODS = [:options, :get, :head, :post, :put, :delete, :trace, :connect, :patch]
|
4
|
+
|
5
|
+
def define_routes(silence_paths, opts)
|
6
|
+
METHODS.each_with_object({}) do |method, routes|
|
7
|
+
routes[method.to_s.upcase] = wrap(opts.delete(method)) + silence_paths
|
8
|
+
routes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/silencer/rack/logger.rb
CHANGED
@@ -1,29 +1,21 @@
|
|
1
1
|
require 'rack/logger'
|
2
|
-
require 'silencer/util'
|
3
2
|
require 'silencer/hush'
|
3
|
+
require 'silencer/methods'
|
4
|
+
require 'silencer/util'
|
4
5
|
|
5
6
|
module Silencer
|
6
7
|
module Rack
|
7
8
|
class Logger < ::Rack::Logger
|
8
|
-
include Silencer::Util
|
9
9
|
include Silencer::Hush
|
10
|
+
include Silencer::Methods
|
11
|
+
include Silencer::Util
|
10
12
|
|
11
13
|
def initialize(app, *args)
|
12
14
|
opts = extract_options!(args)
|
13
15
|
@silence = wrap(opts.delete(:silence))
|
14
|
-
@routes =
|
15
|
-
'OPTIONS' => wrap(opts.delete(:options)) + @silence,
|
16
|
-
'GET' => wrap(opts.delete(:get)) + @silence,
|
17
|
-
'HEAD' => wrap(opts.delete(:head)) + @silence,
|
18
|
-
'POST' => wrap(opts.delete(:post)) + @silence,
|
19
|
-
'PUT' => wrap(opts.delete(:put)) + @silence,
|
20
|
-
'DELETE' => wrap(opts.delete(:delete)) + @silence,
|
21
|
-
'TRACE' => wrap(opts.delete(:trace)) + @silence,
|
22
|
-
'CONNECT' => wrap(opts.delete(:connect)) + @silence,
|
23
|
-
'PATCH' => wrap(opts.delete(:patch)) + @silence,
|
24
|
-
}
|
16
|
+
@routes = define_routes(@silence, opts)
|
25
17
|
|
26
|
-
super
|
18
|
+
super(app, *args)
|
27
19
|
end
|
28
20
|
|
29
21
|
def call(env)
|
@@ -1,33 +1,31 @@
|
|
1
|
+
require 'silencer/hush'
|
2
|
+
require 'silencer/methods'
|
3
|
+
require 'silencer/util'
|
4
|
+
|
1
5
|
module Silencer
|
2
|
-
|
3
|
-
|
4
|
-
::
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
# rubocop:disable Style/ConstantName
|
7
|
+
RailsLogger = begin
|
8
|
+
if Silencer::Environment.rails2?
|
9
|
+
require 'rails/rack/log_tailer'
|
10
|
+
::Rails::Rack::LogTailer
|
11
|
+
else
|
12
|
+
require 'rails/rack/logger'
|
13
|
+
::Rails::Rack::Logger
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
17
|
module Rails
|
11
18
|
class Logger < RailsLogger
|
12
|
-
include Silencer::Util
|
13
19
|
include Silencer::Hush
|
20
|
+
include Silencer::Methods
|
21
|
+
include Silencer::Util
|
14
22
|
|
15
23
|
def initialize(app, *args)
|
16
24
|
opts = extract_options!(args)
|
17
25
|
@silence = wrap(opts.delete(:silence))
|
18
|
-
@routes =
|
19
|
-
|
20
|
-
|
21
|
-
'HEAD' => wrap(opts.delete(:head)) + @silence,
|
22
|
-
'POST' => wrap(opts.delete(:post)) + @silence,
|
23
|
-
'PUT' => wrap(opts.delete(:put)) + @silence,
|
24
|
-
'DELETE' => wrap(opts.delete(:delete)) + @silence,
|
25
|
-
'TRACE' => wrap(opts.delete(:trace)) + @silence,
|
26
|
-
'CONNECT' => wrap(opts.delete(:connect)) + @silence,
|
27
|
-
'PATCH' => wrap(opts.delete(:patch)) + @silence,
|
28
|
-
}
|
29
|
-
|
30
|
-
if normalized_args = normalize(args)
|
26
|
+
@routes = define_routes(@silence, opts)
|
27
|
+
|
28
|
+
if normalized_args = normalize(args) # rubocop:disable Lint/AssignmentInCondition
|
31
29
|
super(app, normalized_args)
|
32
30
|
else
|
33
31
|
super(app)
|
@@ -35,19 +33,45 @@ module Silencer
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def call(env)
|
36
|
+
if silence_request?(env)
|
37
|
+
quiet do
|
38
|
+
super
|
39
|
+
end
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def quiet(&block)
|
48
|
+
if ::Rails.logger.respond_to?(:silence)
|
49
|
+
quiet_with_silence(&block)
|
50
|
+
else
|
51
|
+
quiet_with_log_level(&block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# This is threadsafe in Rails 4.2.6+
|
56
|
+
def quiet_with_silence
|
57
|
+
::Rails.logger.silence do
|
58
|
+
yield
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# This is not threadsafe
|
63
|
+
def quiet_with_log_level
|
38
64
|
old_logger_level = ::Rails.logger.level
|
39
|
-
::Rails.logger.level = ::Logger::ERROR
|
65
|
+
::Rails.logger.level = ::Logger::ERROR
|
40
66
|
|
41
|
-
|
67
|
+
yield
|
42
68
|
ensure
|
43
69
|
# Return back to previous logging level
|
44
70
|
::Rails.logger.level = old_logger_level
|
45
71
|
end
|
46
72
|
|
47
|
-
private
|
48
|
-
|
49
73
|
def normalize(args)
|
50
|
-
|
74
|
+
case args.size
|
51
75
|
when 0 then nil
|
52
76
|
when 1 then args.shift
|
53
77
|
else args
|
data/lib/silencer/util.rb
CHANGED
data/lib/silencer/version.rb
CHANGED
data/silencer.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.files = %w(.yardopts LICENSE.md README.md Rakefile silencer.gemspec)
|
16
16
|
gem.files += Dir.glob("lib/**/*.rb")
|
17
|
-
|
17
|
+
|
18
18
|
gem.test_files = Dir.glob("spec/**/*")
|
19
19
|
|
20
20
|
gem.require_paths = ["lib"]
|
@@ -1,62 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Silencer::Rack::Logger do
|
4
|
-
let(:app) {
|
4
|
+
let(:app) { ->(_env) { [200, {}, ''] } }
|
5
5
|
|
6
6
|
it 'quiets the log when configured with a silenced path' do
|
7
7
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
8
8
|
|
9
|
-
Silencer::Rack::Logger.new(app, :
|
10
|
-
|
9
|
+
Silencer::Rack::Logger.new(app, silence: ['/'])
|
10
|
+
.call(Rack::MockRequest.env_for('/'))
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'quiets the log when configured with a regex' do
|
14
14
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
15
15
|
|
16
|
-
Silencer::Rack::Logger.new(app, :
|
17
|
-
|
16
|
+
Silencer::Rack::Logger.new(app, silence: [/assets/])
|
17
|
+
.call(Rack::MockRequest.env_for('/assets/application.css'))
|
18
18
|
end
|
19
19
|
|
20
20
|
%w(OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT PATCH).each do |method|
|
21
21
|
it "quiets the log when configured with a silenced path for #{method} requests" do
|
22
22
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
23
23
|
|
24
|
-
Silencer::Rack::Logger.new(app, method.downcase.to_sym => ['/'])
|
25
|
-
|
24
|
+
Silencer::Rack::Logger.new(app, method.downcase.to_sym => ['/'])
|
25
|
+
.call(Rack::MockRequest.env_for('/', method: method))
|
26
26
|
end
|
27
27
|
|
28
28
|
it "quiets the log when configured with a regex for #{method} requests" do
|
29
29
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
30
30
|
|
31
|
-
Silencer::Rack::Logger.new(app, method.downcase.to_sym => [/assets/])
|
32
|
-
|
31
|
+
Silencer::Rack::Logger.new(app, method.downcase.to_sym => [/assets/])
|
32
|
+
.call(Rack::MockRequest.env_for('/assets/application.css', method: method))
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'quiets the log when configured with a silenced path for non-standard requests' do
|
37
37
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
38
38
|
|
39
|
-
Silencer::Rack::Logger.new(app, :
|
40
|
-
|
39
|
+
Silencer::Rack::Logger.new(app, silence: ['/'])
|
40
|
+
.call(Rack::MockRequest.env_for('/', method: 'UPDATE'))
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'quiets the log when configured with a regex for non-standard requests' do
|
44
44
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
45
45
|
|
46
|
-
Silencer::Rack::Logger.new(app, :
|
47
|
-
|
46
|
+
Silencer::Rack::Logger.new(app, silence: [/assets/])
|
47
|
+
.call(Rack::MockRequest.env_for('/assets/application.css', method: 'UPDATE'))
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'quiets the log when passed a custom header "X-SILENCE-LOGGER"' do
|
51
51
|
expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
|
52
52
|
|
53
|
-
Silencer::Rack::Logger.new(app)
|
54
|
-
|
53
|
+
Silencer::Rack::Logger.new(app)
|
54
|
+
.call(Rack::MockRequest.env_for('/', 'HTTP_X_SILENCE_LOGGER' => 'true'))
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'does not tamper with the response' do
|
58
|
-
response = Silencer::Rack::Logger.new(app)
|
59
|
-
|
58
|
+
response = Silencer::Rack::Logger.new(app)
|
59
|
+
.call(Rack::MockRequest.env_for('/', 'HTTP_X_SILENCE_LOGGER' => 'true'))
|
60
60
|
|
61
61
|
expect(response[0]).to eq(200)
|
62
62
|
end
|
@@ -1,88 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Silencer::Rails::Logger do
|
4
|
-
let(:app) {
|
4
|
+
let(:app) { ->(_env) { [200, {}, ''] } }
|
5
5
|
let(:log_tags) { [:uuid, :queue] }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
context 'quieted' do
|
8
|
+
before do
|
9
|
+
expect_any_instance_of(Silencer::Rails::Logger).to receive(:quiet).at_least(:once).and_call_original
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
it 'quiets the log when configured with a silenced path' do
|
13
|
+
Silencer::Rails::Logger.new(app, silence: ['/'])
|
14
|
+
.call(Rack::MockRequest.env_for('/'))
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
it 'quiets the log when configured with a regex' do
|
18
|
+
Silencer::Rails::Logger.new(app, silence: [/assets/])
|
19
|
+
.call(Rack::MockRequest.env_for('/assets/application.css'))
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
%w(OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT PATCH).each do |method|
|
23
|
+
it "quiets the log when configured with a silenced path for #{method} requests" do
|
24
|
+
Silencer::Rails::Logger.new(app, method.downcase.to_sym => ['/'])
|
25
|
+
.call(Rack::MockRequest.env_for('/', method: method))
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
it "quiets the log when configured with a regex for #{method} requests" do
|
29
|
+
Silencer::Rails::Logger.new(app, method.downcase.to_sym => [/assets/])
|
30
|
+
.call(Rack::MockRequest.env_for('/assets/application.css', method: method))
|
31
|
+
end
|
32
|
+
end
|
27
33
|
|
28
|
-
|
29
|
-
|
34
|
+
it 'quiets the log when configured with a silenced path for non-standard requests' do
|
35
|
+
Silencer::Rails::Logger.new(app, silence: ['/'])
|
36
|
+
.call(Rack::MockRequest.env_for('/', method: 'UPDATE'))
|
30
37
|
end
|
31
38
|
|
32
|
-
it
|
33
|
-
|
34
|
-
|
39
|
+
it 'quiets the log when configured with a regex for non-standard requests' do
|
40
|
+
Silencer::Rails::Logger.new(app, silence: [/assets/])
|
41
|
+
.call(Rack::MockRequest.env_for('/assets/application.css', method: 'UPDATE'))
|
42
|
+
end
|
35
43
|
|
36
|
-
|
37
|
-
|
44
|
+
it 'quiets the log when passed a custom header "X-SILENCE-LOGGER"' do
|
45
|
+
Silencer::Rails::Logger.new(app)
|
46
|
+
.call(Rack::MockRequest.env_for('/', 'HTTP_X_SILENCE_LOGGER' => 'true'))
|
38
47
|
end
|
39
|
-
end
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
it 'does not tamper with the response' do
|
50
|
+
response = Silencer::Rails::Logger.new(app)
|
51
|
+
.call(Rack::MockRequest.env_for('/', 'HTTP_X_SILENCE_LOGGER' => 'true'))
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
53
|
+
expect(response[0]).to eq(200)
|
54
|
+
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
if Silencer::Environment.tagged_logger?
|
57
|
+
it 'instantiates with an optional taggers array' do
|
58
|
+
Silencer::Rails::Logger.new(app, log_tags, silence: ['/'])
|
59
|
+
.call(Rack::MockRequest.env_for('/'))
|
60
|
+
end
|
52
61
|
|
53
|
-
|
54
|
-
|
62
|
+
it 'instantiates with an optional taggers array passed as args' do
|
63
|
+
Silencer::Rails::Logger.new(app, :uuid, :queue, silence: ['/'])
|
64
|
+
.call(Rack::MockRequest.env_for('/'))
|
65
|
+
end
|
66
|
+
end
|
55
67
|
end
|
56
68
|
|
57
|
-
it '
|
58
|
-
|
59
|
-
with(::Logger::ERROR).at_least(:once)
|
60
|
-
|
61
|
-
Silencer::Rails::Logger.new(app).
|
62
|
-
call(Rack::MockRequest.env_for("/", 'HTTP_X_SILENCE_LOGGER' => 'true'))
|
63
|
-
end
|
69
|
+
it 'silences' do
|
70
|
+
logger = Silencer::Rails::Logger.new(app, silence: ['/'])
|
64
71
|
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
if ::Rails.logger.respond_to?(:silence)
|
73
|
+
expect(::Rails.logger).to receive(:silence).at_least(:once)
|
74
|
+
else
|
75
|
+
expect(::Rails.logger).to receive(:level=)
|
76
|
+
.with(::Logger::ERROR).at_least(:once)
|
77
|
+
end
|
68
78
|
|
69
|
-
|
79
|
+
logger.call(Rack::MockRequest.env_for('/'))
|
70
80
|
end
|
71
|
-
|
72
|
-
it 'instantiates with an optional taggers array' do
|
73
|
-
expect(::Rails.logger).to receive(:level=).
|
74
|
-
with(::Logger::ERROR).at_least(:once)
|
75
|
-
|
76
|
-
Silencer::Rails::Logger.new(app, log_tags, :silence => ['/']).
|
77
|
-
call(Rack::MockRequest.env_for("/"))
|
78
|
-
end if Silencer::Environment.tagged_logger?
|
79
|
-
|
80
|
-
it 'instantiates with an optional taggers array passed as args' do
|
81
|
-
expect(::Rails.logger).to receive(:level=).
|
82
|
-
with(::Logger::ERROR).at_least(:once)
|
83
|
-
|
84
|
-
Silencer::Rails::Logger.new(app, :uuid, :queue, :silence => ['/']).
|
85
|
-
call(Rack::MockRequest.env_for("/"))
|
86
|
-
end if Silencer::Environment.tagged_logger?
|
87
|
-
|
88
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
unless ENV['CI']
|
2
2
|
require 'simplecov'
|
3
3
|
SimpleCov.start do
|
4
|
-
add_filter '.bundle'
|
5
4
|
add_group 'Silencer', 'lib/silencer'
|
6
5
|
add_group 'Specs', 'spec'
|
7
6
|
end
|
@@ -17,7 +16,11 @@ io = StringIO.new
|
|
17
16
|
|
18
17
|
begin
|
19
18
|
require 'rails'
|
20
|
-
::Rails.logger = ::
|
19
|
+
::Rails.logger = if Rails::VERSION::MAJOR >= 4
|
20
|
+
::ActiveSupport::Logger.new(io)
|
21
|
+
else
|
22
|
+
::Logger.new(io)
|
23
|
+
end
|
21
24
|
rescue LoadError
|
22
25
|
require 'activesupport'
|
23
26
|
RAILS_ENV = 'test'
|
@@ -36,5 +39,4 @@ RSpec.configure do |config|
|
|
36
39
|
config.before(:each) do
|
37
40
|
allow(::Rails.logger).to receive(:level=).with(anything)
|
38
41
|
end
|
39
|
-
|
40
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: silencer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Agalloco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Selectively quiet your Rails/Rack logger on a per-route basis
|
14
14
|
email:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/silencer/environment.rb
|
26
26
|
- lib/silencer/hush.rb
|
27
27
|
- lib/silencer/logger.rb
|
28
|
+
- lib/silencer/methods.rb
|
28
29
|
- lib/silencer/rack/logger.rb
|
29
30
|
- lib/silencer/rails/logger.rb
|
30
31
|
- lib/silencer/util.rb
|
@@ -48,12 +49,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
49
|
version: '0'
|
49
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
51
|
requirements:
|
51
|
-
- - "
|
52
|
+
- - ">="
|
52
53
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
+
version: '0'
|
54
55
|
requirements: []
|
55
56
|
rubyforge_project:
|
56
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.5.1
|
57
58
|
signing_key:
|
58
59
|
specification_version: 4
|
59
60
|
summary: Selectively quiet your Rails/Rack logger on a per-route basis
|
@@ -62,4 +63,3 @@ test_files:
|
|
62
63
|
- spec/silencer/rack/logger_spec.rb
|
63
64
|
- spec/silencer/rails/logger_spec.rb
|
64
65
|
- spec/spec_helper.rb
|
65
|
-
has_rdoc:
|