quiet_logger 1.0.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
+ SHA256:
3
+ metadata.gz: 1ae7192146de8bb704c786f4c129dc33b3eece9d1c0b6e0fdb417274c70eb25d
4
+ data.tar.gz: c7c8971f79e92aede026a7e36ebfea13ff329062c85598e999017c60e5978ef2
5
+ SHA512:
6
+ metadata.gz: 7f5057c20db5903f1f97c620e892074ab1cfcf3dc4aa53f88b62c514a41c722593f0fd36205350c62e5e86eadac606d632629d1c62a91e297a300138e2cb8593
7
+ data.tar.gz: a2e71f9d7c810866e316f93c0b0dec3f88e95fddaa78be5b80891e627eab4f0989a7908697fe8f7aee6edaca12b354e7b1dcff61b15ac33cd854ad8dfb85a048
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 1.0.0
8
+
9
+ ### Added
10
+ - Add QuietLogger class to wrap other loggers but with a higher severity level to quiet their output.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Brian Durand
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,59 @@
1
+ [![Continuous Integration](https://github.com/bdurand/quiet_logger/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/quiet_logger/actions/workflows/continuous_integration.yml)
2
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
3
+
4
+ # QuietLogger
5
+
6
+ This gem provides a mechanism for wrapping a instance of `Logger` with one that produces a less verbose output.
7
+
8
+ This can be used in situations where different parts of an application should produce different levels of output to the logs. A classic example is when using a framework that produces a lot of low value log output. You can normally control this by changing the log level, but that can impact other parts of your application sharing the same logger.
9
+
10
+ For example, in a Rails application ActionCable can log a lot of information to the logs with a severity level of `INFO`. This can produce an excessive amount of output which can bury more important information in the logs. However, increasing the log level would end up turning off info logs for the entire application.
11
+
12
+ You could override the logger to use one with a higher log level, but this requires you to reinitialize the logger with any customiziation you made to it for your application (i.e. output device, format, etc.). With QuietLogger, you can just re-use the logger that has already been defined:
13
+
14
+ ```ruby
15
+ ActionCable.server.config.logger = QuietLogger.new(Rails.logger, level: :warn)
16
+ ```
17
+
18
+ Now all the log messages will still go to the same logger, but with only `WARN` and higher messages from ActionCable.
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ verbose_logger = Logger.new(STDOUT, level: :debug)
24
+ quiet_logger = QuietLogger.new(verbose_logger, level: :warn)
25
+
26
+ verbose_logger.debug("hello") # This is logged
27
+ quiet_logger.debug("hello again") # This is not logged since the level must be "warn" or higher
28
+ quiet_logger.warn("one more time") # This is logged since the level is warn
29
+
30
+ even_quieter_logger = QuietLogger.new(verbose_logger, level: :error)
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ ```ruby
38
+ gem "quiet_logger"
39
+ ```
40
+
41
+ And then execute:
42
+ ```bash
43
+ $ bundle
44
+ ```
45
+
46
+ Or install it yourself as:
47
+ ```bash
48
+ $ gem install quiet_logger
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ Open a pull request on GitHub.
54
+
55
+ Please use the [standardrb](https://github.com/testdouble/standard) syntax and lint your code with `standardrb --fix` before submitting.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+
5
+ # Wrap a Logger in a quieter instance that can have a higher severity level filter.
6
+ #
7
+ # Usage:
8
+ #
9
+ # ```
10
+ # logger = Logger.new(STDOUT)
11
+ # quiet_logger = QuietLogger.new(logger)
12
+ #
13
+ # logger.debug("Stuff") # This statement is logged
14
+ # quiet_logger.debug("More stuff") # This statement is not logged
15
+ # quiet_logger.warn("Other stuff") # This statement logged
16
+ # ```
17
+ #
18
+ # By default the quiet log level is "warn", but you can change to an even higher level:
19
+ #
20
+ # ```
21
+ # QuietLogger.new(logger, level: :error)
22
+ # ```
23
+ #
24
+ # The log level on the `QuietLogger` can only be made more restrictive than the level on the
25
+ # underlying logger. So, if the underlying logger has a level of "info", you cannot set the
26
+ # `QuietLogger` to "debug".
27
+ class QuietLogger < Logger
28
+ # Wrap a logger to have a higher log level.
29
+ def initialize(logger, level: Logger::WARN)
30
+ @logger = logger
31
+ self.level = level
32
+ end
33
+
34
+ # @return [Integer] Returns the log level
35
+ def level
36
+ [@level, @logger.level].max
37
+ end
38
+
39
+ # @api private
40
+ def add(severity, message = nil, progname = nil, &block)
41
+ severity ||= UNKNOWN
42
+ if severity < level
43
+ return true
44
+ end
45
+ @logger.add(severity, message, progname, &block)
46
+ end
47
+ alias_method :log, :add
48
+
49
+ # @api private
50
+ def <<(msg)
51
+ @logger << msg
52
+ end
53
+
54
+ # @api private
55
+ def close
56
+ # no-op
57
+ end
58
+
59
+ # @api private
60
+ def reopen(logdev = nil)
61
+ # no-op
62
+ end
63
+ end
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "quiet_logger"
3
+ spec.version = File.read(File.expand_path("../VERSION", __FILE__)).strip
4
+ spec.authors = ["Brian Durand"]
5
+ spec.email = ["bbdurand@gmail.com"]
6
+
7
+ spec.summary = "A logger implementation that can wrap another logger to increase the log level to reduce noise in the logs."
8
+ spec.homepage = "https://github.com/bdurand/quiet_logger"
9
+ spec.license = "MIT"
10
+
11
+ # Specify which files should be added to the gem when it is released.
12
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
13
+ ignore_files = %w[
14
+ .
15
+ Appraisals
16
+ Gemfile
17
+ Gemfile.lock
18
+ Rakefile
19
+ bin/
20
+ gemfiles/
21
+ spec/
22
+ ]
23
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| ignore_files.any? { |path| f.start_with?(path) } }
25
+ end
26
+
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler"
30
+
31
+ spec.required_ruby_version = ">= 2.5"
32
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quiet_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Durand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - bbdurand@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - VERSION
38
+ - lib/quiet_logger.rb
39
+ - quiet_logger.gemspec
40
+ homepage: https://github.com/bdurand/quiet_logger
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '2.5'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.0.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A logger implementation that can wrap another logger to increase the log
63
+ level to reduce noise in the logs.
64
+ test_files: []