silencer 1.0.0.rc1 → 1.0.0.rc2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7ef75ac63318d241d214b16a854d2aa6b39f8a0
4
+ data.tar.gz: 90825083959582325bd351eb3bc63e839ef8a76f
5
+ SHA512:
6
+ metadata.gz: 6d2e729621956654981408c013ac516d4e2f8ceeb7f81cb60d62112dedc03a03d5fb1f3c57a0fda2d498b3be9aba1a52a24b99620a4337e7a5ca3580e76c6572
7
+ data.tar.gz: af03bee5f2ed1a3aa6a31bbbfa974a86663b10b35517d4d81ba3f332ba77c3760deec246495eb4328676c7d89f637b7c4d8dec61cb5d05f805c82c38d3261c46
data/README.md CHANGED
@@ -27,8 +27,28 @@ Or if you'd prefer, you can pass it regular expressions:
27
27
 
28
28
  config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :silence => [%r{^/assets/}]
29
29
 
30
+ Or you can silence specific request methods only:
31
+
32
+
33
+ config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :get => [%r{^/assets/}], :post => [%r{^/some_path}]
34
+
30
35
  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.
31
36
 
37
+ ### All options
38
+
39
+ Silencer supports the following configuration options.
40
+
41
+ :silence - Silences matching requests regardless of request method
42
+ :get - Silences matching GET requests
43
+ :head - Silences matching HEAD requests
44
+ :post - Silences matching POST requests
45
+ :put - Silences matching PUT requests
46
+ :delete - Silences matching DELETE requests
47
+ :patch - Silences matching PATCH requests
48
+ :trace - Silences matching TRACE requests
49
+ :connect - Silences matching CONNECT requests
50
+ :options - Silences matching OPTIONS requests
51
+
32
52
  ### Rails 2.3
33
53
 
34
54
  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:
@@ -12,7 +12,7 @@ module Silencer
12
12
  end
13
13
 
14
14
  def silent_path?(env)
15
- @silence.any? { |s| s === env['PATH_INFO'] }
15
+ (@routes[env['REQUEST_METHOD']] || @silence).any? { |s| s === env['PATH_INFO'] }
16
16
  end
17
17
 
18
18
  end
@@ -11,6 +11,17 @@ module Silencer
11
11
  def initialize(app, *args)
12
12
  opts = extract_options!(args)
13
13
  @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
+ }
14
25
 
15
26
  super app, *args
16
27
  end
@@ -15,6 +15,17 @@ module Silencer
15
15
  def initialize(app, *args)
16
16
  opts = extract_options!(args)
17
17
  @silence = wrap(opts.delete(:silence))
18
+ @routes = {
19
+ 'OPTIONS' => wrap(opts.delete(:options)) + @silence,
20
+ 'GET' => wrap(opts.delete(:get)) + @silence,
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
+ }
18
29
 
19
30
  if normalized_args = normalize(args.flatten)
20
31
  super(app, normalized_args)
@@ -1,3 +1,3 @@
1
1
  module Silencer
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0.rc2"
3
3
  end
@@ -17,6 +17,36 @@ describe Silencer::Rack::Logger do
17
17
  call(Rack::MockRequest.env_for("/assets/application.css"))
18
18
  end
19
19
 
20
+ %w(OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT PATCH).each do |method|
21
+ it "quiets the log when configured with a silenced path for #{method} requests" do
22
+ expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
23
+
24
+ Silencer::Rack::Logger.new(app, method.downcase.to_sym => ['/']).
25
+ call(Rack::MockRequest.env_for("/", :method => method))
26
+ end
27
+
28
+ it "quiets the log when configured with a regex for #{method} requests" do
29
+ expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
30
+
31
+ Silencer::Rack::Logger.new(app, method.downcase.to_sym => [/assets/]).
32
+ call(Rack::MockRequest.env_for("/assets/application.css", :method => method))
33
+ end
34
+ end
35
+
36
+ it 'quiets the log when configured with a silenced path for non-standard requests' do
37
+ expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
38
+
39
+ Silencer::Rack::Logger.new(app, :silence => ['/']).
40
+ call(Rack::MockRequest.env_for("/", :method => 'UPDATE'))
41
+ end
42
+
43
+ it 'quiets the log when configured with a regex for non-standard requests' do
44
+ expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
45
+
46
+ Silencer::Rack::Logger.new(app, :silence => [/assets/]).
47
+ call(Rack::MockRequest.env_for("/assets/application.css", :method => 'UPDATE'))
48
+ end
49
+
20
50
  it 'quiets the log when passed a custom header "X-SILENCE-LOGGER"' do
21
51
  expect_any_instance_of(::Logger).to receive(:level=).with(::Logger::ERROR)
22
52
 
@@ -20,6 +20,40 @@ describe Silencer::Rails::Logger do
20
20
  call(Rack::MockRequest.env_for("/assets/application.css"))
21
21
  end
22
22
 
23
+ %w(OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT PATCH).each do |method|
24
+ it "quiets the log when configured with a silenced path for #{method} requests" do
25
+ expect(::Rails.logger).to receive(:level=).
26
+ with(::Logger::ERROR).at_least(:once)
27
+
28
+ Silencer::Rails::Logger.new(app, method.downcase.to_sym => ['/']).
29
+ call(Rack::MockRequest.env_for("/", :method => method))
30
+ end
31
+
32
+ it "quiets the log when configured with a regex for #{method} requests" do
33
+ expect(::Rails.logger).to receive(:level=).
34
+ with(::Logger::ERROR).at_least(:once)
35
+
36
+ Silencer::Rails::Logger.new(app, method.downcase.to_sym => [/assets/]).
37
+ call(Rack::MockRequest.env_for("/assets/application.css", :method => method))
38
+ end
39
+ end
40
+
41
+ it 'quiets the log when configured with a silenced path for non-standard requests' do
42
+ expect(::Rails.logger).to receive(:level=).
43
+ with(::Logger::ERROR).at_least(:once)
44
+
45
+ Silencer::Rails::Logger.new(app, :silence => ['/']).
46
+ call(Rack::MockRequest.env_for("/", :method => 'UPDATE'))
47
+ end
48
+
49
+ it 'quiets the log when configured with a regex for non-standard requests' do
50
+ expect(::Rails.logger).to receive(:level=).
51
+ with(::Logger::ERROR).at_least(:once)
52
+
53
+ Silencer::Rails::Logger.new(app, :silence => [/assets/]).
54
+ call(Rack::MockRequest.env_for("/assets/application.css", :method => 'UPDATE'))
55
+ end
56
+
23
57
  it 'quiets the log when passed a custom header "X-SILENCE-LOGGER"' do
24
58
  expect(::Rails.logger).to receive(:level=).
25
59
  with(::Logger::ERROR).at_least(:once)
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silencer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
5
- prerelease: 6
4
+ version: 1.0.0.rc2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steve Agalloco
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-20 00:00:00.000000000 Z
11
+ date: 2014-02-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Selectively quiet your Rails/Rack logger on a per-route basis
15
14
  email:
@@ -37,30 +36,26 @@ files:
37
36
  - spec/spec_helper.rb
38
37
  homepage: http://github.com/spagalloco/silencer
39
38
  licenses: []
39
+ metadata: {}
40
40
  post_install_message:
41
41
  rdoc_options: []
42
42
  require_paths:
43
43
  - lib
44
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
45
  requirements:
47
- - - ! '>='
46
+ - - '>='
48
47
  - !ruby/object:Gem::Version
49
48
  version: '0'
50
- segments:
51
- - 0
52
- hash: 3624886497730780016
53
49
  required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
50
  requirements:
56
- - - ! '>'
51
+ - - '>'
57
52
  - !ruby/object:Gem::Version
58
53
  version: 1.3.1
59
54
  requirements: []
60
55
  rubyforge_project:
61
- rubygems_version: 1.8.23
56
+ rubygems_version: 2.0.14
62
57
  signing_key:
63
- specification_version: 3
58
+ specification_version: 4
64
59
  summary: Selectively quiet your Rails/Rack logger on a per-route basis
65
60
  test_files:
66
61
  - spec/log/test.log