tagged_logger 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -1
- data/lib/tagged_logger.rb +10 -6
- data/tagged_logger.rb +1 -0
- data/test/test.rb +28 -0
- metadata +6 -6
- data/VERSION +0 -1
data/README.markdown
CHANGED
@@ -9,7 +9,8 @@ Every time you want to log something, simply write:
|
|
9
9
|
and do not worry about what kind of logger you use and how your code accesses it.
|
10
10
|
You may configure these things later, one day writing to STDOUT works for you, another
|
11
11
|
day you'll need something more sophisticated, like several log files each serving
|
12
|
-
different components and for different audience.
|
12
|
+
different components and for different audience. [Here](http://afurmanov.com/2009/10/19/tagged-logger-introduction)
|
13
|
+
I have described in more details why I created it.
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
$ gem install tagged_logger
|
data/lib/tagged_logger.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
require '
|
2
|
+
require 'hashery/dictionary'
|
3
3
|
|
4
4
|
class TaggedLogger
|
5
5
|
@rename_rules = Dictionary.new
|
@@ -13,8 +13,13 @@ class TaggedLogger
|
|
13
13
|
init
|
14
14
|
end
|
15
15
|
|
16
|
-
def rules(&block)
|
17
|
-
|
16
|
+
def rules(options = {}, &block)
|
17
|
+
klasses = []
|
18
|
+
# klasses << AbstractController::Base if Object.const_defined? :AbstractController
|
19
|
+
klasses << Object
|
20
|
+
override = options.delete :override
|
21
|
+
klasses = klasses.select{ |klass| !klass.respond_to?(:logger, true)} if !override
|
22
|
+
klasses.each{ |klass| inject_logger_method_in_call_chain(klass)}
|
18
23
|
instance_eval(&block)
|
19
24
|
end
|
20
25
|
|
@@ -119,9 +124,8 @@ class TaggedLogger
|
|
119
124
|
end
|
120
125
|
end
|
121
126
|
|
122
|
-
def
|
123
|
-
|
124
|
-
Object.class_eval do
|
127
|
+
def inject_logger_method_in_call_chain(definee_klass)
|
128
|
+
definee_klass.class_eval do
|
125
129
|
def logger
|
126
130
|
klass = self.class == Class ? self : self.class
|
127
131
|
result = klass.class_eval do
|
data/tagged_logger.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/tagged_logger.rb'
|
data/test/test.rb
CHANGED
@@ -35,6 +35,34 @@ class TaggedLoggerTest < Test::Unit::TestCase
|
|
35
35
|
assert_nothing_raised { Class.new.logger }
|
36
36
|
end
|
37
37
|
|
38
|
+
should "not override exsiting #logger method" do
|
39
|
+
GlobalObject1 = Object
|
40
|
+
GlobalObject1.instance_eval { define_method(:logger){@@stub_out}}
|
41
|
+
class GlobalObject1
|
42
|
+
def foo; logger.write("debug"); end
|
43
|
+
end
|
44
|
+
TaggedLogger.rules do
|
45
|
+
reset
|
46
|
+
debug(/.*/) { |level, tag, msg| debugger; @@stub_out.write("hmmm, something new") }
|
47
|
+
end
|
48
|
+
mock(@@stub_out).write("debug")
|
49
|
+
Object.new.foo
|
50
|
+
end
|
51
|
+
|
52
|
+
should "override exsiting #logger method when intialized with :override" do
|
53
|
+
GlobalObject2 = Object
|
54
|
+
class GlobalObject2
|
55
|
+
def logger; @logger ||= Logger.new('/dev/null'); end
|
56
|
+
def foo; logger.debug("debug"); end
|
57
|
+
end
|
58
|
+
TaggedLogger.rules(:override => true) do
|
59
|
+
reset
|
60
|
+
debug(/.*/) { |level, tag, msg| @@stub_out.write(msg) }
|
61
|
+
end
|
62
|
+
mock(@@stub_out).write("debug")
|
63
|
+
Object.new.foo
|
64
|
+
end
|
65
|
+
|
38
66
|
context "everything gets logged to @@stub_out;" do
|
39
67
|
setup do
|
40
68
|
TaggedLogger.rules do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tagged_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aleksandr Furmanov
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-17 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: hashery
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- MIT-LICENSE
|
75
75
|
- Rakefile
|
76
76
|
- README.markdown
|
77
|
-
-
|
77
|
+
- tagged_logger.rb
|
78
78
|
- lib/tagged_logger.rb
|
79
79
|
- test/expected_examples_output.txt
|
80
80
|
- test/test.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.1
|