void_logger 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjE1N2IxN2IxM2NjNDM0ZWFlOThiZTYwMGNhZjk0MTE2OGVjMzllMQ==
5
+ data.tar.gz: !binary |-
6
+ MTYxYWMzODRiZWJhYjY1YzNkOWRjMTc0ZGI2ODlhM2JhNjM5MTUwNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MGQxNDBhMDljNGE3YTg0ZTAxOWRlMTFiOTRjYzU3M2VhNTUwNDM2MWEyMzY1
10
+ MTY5MWNjNTMyZTJhZTEyODhiOTIzMmE1NDJjOGY5NzBmNjdhNTkzYzQxMzQx
11
+ NDAzNGQ3YmRlMTc2ZWIyODM1MTU2YWJkOGZjMGI5ZWVlZTdkOTk=
12
+ data.tar.gz: !binary |-
13
+ NjE0OTRiNzQxMWY4OWJlZDBiZDNlNGM4ZjhiNTAxODYwNmMyMjEzNzU5NDEz
14
+ YzQzOGY1MGZlYjk3NDVkOTM0NDNjZGU5ZWUwZTU5NTVmOWY3ODliYTA4YWU3
15
+ NWQ1YTUyNzUxYTA4NGYyY2Y3MmIwZTZlODE2MWExMTZjY2Y2MjU=
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use 1.9.3@void_logger
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in void_logger.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Denis Jean
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # VoidLogger
2
+
3
+ VoidLogger is a Ruby logger that logs into nothing, void or still nowhere.
4
+
5
+ ## Purpose
6
+
7
+ A VoidLogger instance is useful when you want to log things in your class or module but do not necessarily want those traces to go somewhere. Replace the current logger with a VoidLogger instance and nobody will hear your code scream.
8
+
9
+ The VoidLogger::LoggerMixin module comes in support of this approach. Once included in a module or class, it defines a logger attribute initialized to a VoidLogger instance. Later on, you can use a different logger simply by assigning this logger attribute with your own ::Logger variant.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'void_logger'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install void_logger
26
+
27
+ ## Usage
28
+
29
+ Start by requiring the gem:
30
+
31
+ ```ruby
32
+ require 'void_logger'
33
+ ```
34
+
35
+ Then you can use the logger:
36
+
37
+ ```ruby
38
+ logger = VoidLogger.new
39
+ logger.info "TEST" # nothing will be logged
40
+ ```
41
+
42
+ You can also include the mixin in your module/class:
43
+
44
+ ```ruby
45
+ require 'void_logger'
46
+
47
+ class Test
48
+ include VoidLogger::LoggerMixin
49
+
50
+ def initialize(logger=nil)
51
+ self.logger = logger
52
+ end
53
+ end
54
+ ```
55
+
56
+ This mixin brings two members to your module/class:
57
+ - logger: It will look up all the ancestors to find a logger method and use it if it finds one or return a VoidLogger.new
58
+ - fallback_logger: The logger you can use in the class you mix VoidLogger::LoggerMixin into. Return the fallback logger (as defined above) unless you explicitly set a logger with the logger= method.
59
+
60
+ You can reset the fallback logger by calling:
61
+
62
+ ```ruby
63
+ t = Test.new
64
+ t.reset_fallback_logger
65
+ ```
66
+
67
+ Resetting the fallback logger can be useful when a new logger was defined on one of the ancestors.
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it ( https://github.com/[my-github-username]/void_logger/fork )
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,28 @@
1
+ require 'logger'
2
+
3
+ class VoidLogger < ::Logger
4
+ VERSION = "0.1"
5
+
6
+ def initialize(logdev=nil)
7
+ super(logdev)
8
+ end
9
+
10
+ def add(severity, message = nil, progname = nil, &block)
11
+ return true
12
+ end
13
+
14
+ module LoggerMixin
15
+
16
+ attr_writer :logger
17
+ attr_reader :fallback_logger
18
+
19
+ def logger
20
+ @fallback_logger ||= (super rescue nil) || VoidLogger.new
21
+ @logger || @fallback_logger
22
+ end
23
+
24
+ def reset_fallback_logger
25
+ @fallback_logger = nil
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'void_logger'
3
+
4
+ gem "minitest"
5
+ require 'minitest/autorun'
@@ -0,0 +1,64 @@
1
+ require 'minitest_helper'
2
+ require 'logger'
3
+
4
+ LOG_FILE_NAME = 'test/logfile.log'
5
+ LOGGER = Logger.new LOG_FILE_NAME
6
+
7
+ class TestVoidLogger < Minitest::Test
8
+ def setup
9
+ @filepath = LOG_FILE_NAME
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm @filepath, force: true
14
+ end
15
+
16
+ def test_nothing_logged
17
+ logger = VoidLogger.new(@filepath)
18
+ logger.info "Should not be logged"
19
+
20
+ string = File.read(@filepath)
21
+ assert !string.include?("Should not be logged")
22
+ end
23
+
24
+ def test_logger_mixin
25
+ b = B.new
26
+
27
+ assert b.logger.is_a?(VoidLogger)
28
+
29
+ b = B.new(true)
30
+ assert_equal LOGGER, b.logger
31
+
32
+ b.remove_logger
33
+ b.reset_fallback_logger
34
+ assert b.logger.is_a?(VoidLogger)
35
+
36
+ b.logger = LOGGER
37
+ assert_equal LOGGER, b.logger
38
+
39
+ b.logger = nil
40
+ assert b.logger.is_a?(VoidLogger)
41
+ end
42
+ end
43
+
44
+ class A
45
+ def initialize(log=false)
46
+ if log
47
+ self.class.send(:define_method, :logger) do
48
+ LOGGER
49
+ end
50
+ end
51
+ end
52
+
53
+ def remove_logger
54
+ self.class.send(:remove_method, :logger)
55
+ end
56
+ end
57
+
58
+ class B < A
59
+ include VoidLogger::LoggerMixin
60
+
61
+ def initialize(log=false)
62
+ super(log)
63
+ end
64
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'void_logger'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "void_logger"
8
+ spec.version = VoidLogger::VERSION
9
+ spec.authors = ["Denis Jean", "Laurent Farcy"]
10
+ spec.email = ["denis.jean@ecairn.com", "laurent.farcy@ecairn.com"]
11
+ spec.summary = %q{VoidLogger is a Ruby logger that logs into the void.}
12
+
13
+ spec.description = <<-EOF
14
+ A VoidLogger instance is useful when you want to log things in
15
+ your class or module but do not necessarily want those traces to go somewhere.
16
+ Replace the current logger with a VoidLogger instance and nobody will hear your code scream.
17
+ EOF
18
+
19
+ spec.homepage = "https://github.com/ecairn/void_logger"
20
+ spec.license = "MIT"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0")
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.7"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.5"
30
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: void_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Denis Jean
8
+ - Laurent Farcy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '5.5'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '5.5'
56
+ description: ! " A VoidLogger instance is useful when you want to log things in\n
57
+ \ your class or module but do not necessarily want those traces to go somewhere.\n
58
+ \ Replace the current logger with a VoidLogger instance and nobody will hear your
59
+ code scream.\n"
60
+ email:
61
+ - denis.jean@ecairn.com
62
+ - laurent.farcy@ecairn.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - .rvmrc
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/void_logger.rb
74
+ - test/minitest_helper.rb
75
+ - test/test_void_logger.rb
76
+ - void_logger.gemspec
77
+ homepage: https://github.com/ecairn/void_logger
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: VoidLogger is a Ruby logger that logs into the void.
101
+ test_files:
102
+ - test/minitest_helper.rb
103
+ - test/test_void_logger.rb