null_logger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # Null Logger
2
+
3
+ It's nice to be able to inject a Logger into libraries to see what's
4
+ going on, but handling all that logging and providing sane defaults can
5
+ be rather difficult.
6
+
7
+ If we use a Null Logger - a logger which does nothing but which supports
8
+ the Logger interface - we can pass that responsibility off to those who
9
+ care about logging.
10
+
11
+
12
+ ## Usage
13
+
14
+ In your `Gemfile`:
15
+
16
+ gem 'null_logger'
17
+
18
+ In your code you can use the NullLogger instance just like a real
19
+ Logger:
20
+
21
+ require 'null_logger'
22
+ logger = NullLogger.instance
23
+ logger.debug "Foo"
24
+ logger.info "Bar"
25
+ logger.warn "Baz"
26
+ logger.error "Qux"
27
+ logger.fatal "Quux"
28
+
29
+ Of course, you'll probably want to allow people the option to pass in a
30
+ logger, otherwise there's not much point, so your classes end up looking
31
+ something like this:
32
+
33
+ class Groml
34
+ attr_accessor :logger
35
+ private :logger=, :logger
36
+
37
+ def initialize logger = nil
38
+ self.logger = logger || NullLogger.instance
39
+ end
40
+
41
+ def execute
42
+ logger.debug "Starting execute run..."
43
+ end
44
+ end
45
+
46
+
47
+ ## Authors
48
+
49
+ Craig R Webster <http://barkingiguana.com/>
@@ -0,0 +1,12 @@
1
+ require 'null_logger/version'
2
+ require 'null_logger/logger'
3
+
4
+ module NullLogger
5
+ def self.instance
6
+ @instance ||= NullLogger::Logger.new
7
+ end
8
+
9
+ def self.reset!
10
+ @instance = nil
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module NullLogger
2
+ class Logger
3
+ # To get the Logger API you can run this:
4
+ # (Logger.instance_methods.sort - Logger.methods).sort
5
+ [ :<<, :add, :close, :datetime_format,
6
+ :datetime_format=, :debug, :debug?, :error, :error?, :fatal,
7
+ :fatal?, :formatter, :formatter=, :info, :info?, :level, :level=,
8
+ :log, :progname, :progname=, :sev_threshold, :sev_threshold=,
9
+ :unknown, :warn, :warn? ].each do |method_name|
10
+ define_method method_name do |*args| end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module NullLogger
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: null_logger
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Craig R Webster
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-24 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Logging is really useful but handling log files and providing sane defaults is hard. Let those that care about the logging configure their own Logger and give it to us, we'll just pass sane messages to that implementation.
18
+ email:
19
+ - craig@barkingiguana.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - lib/null_logger/logger.rb
28
+ - lib/null_logger/version.rb
29
+ - lib/null_logger.rb
30
+ - README.md
31
+ has_rdoc: true
32
+ homepage:
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.6.2
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: An implementation of the Logger API that does nothing.
59
+ test_files: []
60
+