log_shusher 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: 40f4786865e36b0675ef2e3db78d2d03c9f07952
4
+ data.tar.gz: 350e3ff9a90bdcecdc89bb2485a341991e057a1d
5
+ SHA512:
6
+ metadata.gz: e4a5a0396eff4c754da612c8df01ab76bdd689deb9824eef9d01235a54a80a27c04f5c0c42eec6d33a1f15b9e4b9655201887af1e59472bb3f1ba068e55183d7
7
+ data.tar.gz: 3d1ab2b2548d16c84ce8e3db3b88b3ef52445c52557d0f32baed7b51eb45fa45fc727a80527c14fa50c0d7136743dbbb5555c4a0e19f6dfc145b7da80d119363
data/MIT-LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2014 Raúl Murciano
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Log Shusher
2
+
3
+ Silence your Rails logs under certain conditions.
4
+
5
+ ![](https://raw.githubusercontent.com/raul/log_shusher/master/shusher.jpg)
6
+
7
+ ## Installation
8
+
9
+ Add the gem to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'log_shusher'
13
+ ```
14
+
15
+ and run
16
+
17
+ ```bash
18
+ bundle
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Add the following code in an initializer (e.g: `config/initializers/log_shusher.rb`) or in an environment configuration file (e.g: `config/environments/development.rb`):
24
+
25
+ ```ruby
26
+ LogShusher.shush do |env|
27
+ # expression
28
+ end
29
+ ```
30
+
31
+ The `env` parameter is the [Rack environment hash](http://rack.rubyforge.org/doc/SPEC.html) corresponding to the current request. The request will be logged if the expression inside the block evaluates to `nil` or `false`.
32
+
33
+ Examples:
34
+
35
+ ```ruby
36
+ # Don't log any request
37
+ LogShusher.shush do |env|
38
+ true
39
+ end
40
+
41
+ # Don't log asset requests
42
+ LogShusher.shush do |env|
43
+ env['PATH_INFO'].to_s.include? '/assets/'
44
+ end
45
+
46
+ # Don't log requests for certain file extensions
47
+ LogShusher.shush do |env|
48
+ exts = %w{ .ico .js .css .gif .png .jpeg .jpg }
49
+ exts.any? { |ext| env['PATH_INFO'].to_s.ends_with?(ext) }
50
+ end
51
+ ```
52
+
53
+ ## License
54
+
55
+ Released under the MIT License, Copyright (c) 2014 - To infity... and beyond! Raúl Murciano.
@@ -0,0 +1,52 @@
1
+ # Requests will be logged if the following block evaluates to nil or false:
2
+ #
3
+ # LogShusher.shush do |env|
4
+ # # ...
5
+ # end
6
+
7
+ module LogShusher
8
+ extend self
9
+ attr_accessor :shush_condition
10
+
11
+ def shush(&block)
12
+ self.shush_condition = block
13
+ shush_rails
14
+ shush_rack
15
+ end
16
+
17
+ def shush?(env)
18
+ self.shush_condition.call env
19
+ end
20
+
21
+ private
22
+
23
+ # Sets Rails.logger.level to ERROR when .shush? returns true
24
+ def shush_rails
25
+ ::Rails::Rack::Logger.class_eval do
26
+ def call_app_with_shushed_logs(request, env)
27
+ logger_level = Rails.logger.level
28
+ Rails.logger.level = Logger::ERROR if LogShusher.shush?(env)
29
+ call_app_without_shushed_logs(request, env).tap do
30
+ Rails.logger.level = logger_level
31
+ end
32
+ end
33
+
34
+ alias_method_chain :call_app, :shushed_logs
35
+ end
36
+ end
37
+
38
+ # Skips Rack logging when .shush? returns true
39
+ def shush_rack
40
+ ::Rack::CommonLogger.class_eval do
41
+ def call_with_shushed_logs(env)
42
+ if LogShusher.shush?(env)
43
+ @app.call(env)
44
+ else
45
+ call_without_shushed_logs(env)
46
+ end
47
+ end
48
+
49
+ alias_method_chain :call, :shushed_logs
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'log_shusher'
3
+ spec.version = '1.0'
4
+ spec.summary = 'Silence your Rails logs under certain conditions.'
5
+ spec.homepage = 'https://github.com/raul/log_shusher'
6
+ spec.author = 'Raul Murciano'
7
+ spec.email = 'raul@murciano.net'
8
+ spec.licenses = ['MIT']
9
+ spec.files = %w(
10
+ log_shusher.gemspec
11
+ README.md
12
+ MIT-LICENSE
13
+ lib/log_shusher.rb
14
+ ) + Dir['lib/*.rb']
15
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_shusher
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Raul Murciano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: raul@murciano.net
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - MIT-LICENSE
20
+ - README.md
21
+ - lib/log_shusher.rb
22
+ - log_shusher.gemspec
23
+ homepage: https://github.com/raul/log_shusher
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.2.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Silence your Rails logs under certain conditions.
47
+ test_files: []