lumber 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/VERSION +1 -1
- data/lib/lumber/logger_support.rb +2 -15
- data/lib/lumber/lumber.rb +16 -20
- data/test/logger_support_test.rb +12 -5
- metadata +9 -3
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.6
|
@@ -5,22 +5,9 @@ module Lumber
|
|
5
5
|
module LoggerSupport
|
6
6
|
|
7
7
|
def self.included(receiver)
|
8
|
-
receiver.
|
9
|
-
class_inheritable_accessor :logger
|
10
|
-
last_logger = nil
|
11
|
-
name_parts = self.name.split("::")
|
12
|
-
name_parts.insert(0, Lumber::BASE_LOGGER)
|
13
|
-
name_parts.each_with_index do |part, i|
|
14
|
-
partial = name_parts[0..i].join("::")
|
15
|
-
last_logger = Log4r::Logger[partial]
|
16
|
-
if ! last_logger
|
17
|
-
last_logger = Log4r::Logger.new(partial)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
self.logger = last_logger
|
21
|
-
end
|
8
|
+
Lumber.setup_logger_hierarchy(receiver.name, "#{Lumber::BASE_LOGGER}::#{receiver.name}")
|
22
9
|
end
|
23
10
|
|
24
11
|
end
|
25
|
-
|
12
|
+
|
26
13
|
end
|
data/lib/lumber/lumber.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "socket"
|
2
2
|
|
3
|
+
require "active_support/core_ext/string/inflections"
|
4
|
+
|
3
5
|
begin
|
4
6
|
# rails(active_support) 2
|
5
7
|
require "active_support/core_ext/duplicable"
|
@@ -72,23 +74,18 @@ module Lumber
|
|
72
74
|
def self.setup_logger_hierarchy(class_name, class_logger_fullname)
|
73
75
|
@@registered_loggers[class_name] = class_logger_fullname
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
names.each do |name|
|
78
|
-
root ||= Object
|
79
|
-
if root.const_defined?(name)
|
80
|
-
obj = root.const_get(name)
|
81
|
-
root = obj
|
82
|
-
else
|
83
|
-
obj = nil
|
84
|
-
end
|
85
|
-
end
|
77
|
+
begin
|
78
|
+
clazz = class_name.constantize
|
86
79
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
80
|
+
if clazz.respond_to? :class_inheritable_accessor
|
81
|
+
clazz.class_eval do
|
82
|
+
class_inheritable_accessor :logger
|
83
|
+
self.logger = Log4r::Logger.new(class_logger_fullname)
|
84
|
+
end
|
91
85
|
end
|
86
|
+
|
87
|
+
rescue NameError
|
88
|
+
# The class hasn't been defined yet. No problem, we've registered the logger for when the class is created.
|
92
89
|
end
|
93
90
|
end
|
94
91
|
|
@@ -98,9 +95,9 @@ module Lumber
|
|
98
95
|
# for classes as they get defined.
|
99
96
|
def self.register_inheritance_handler()
|
100
97
|
return if defined?(Object.inherited_with_lumber_log4r)
|
101
|
-
|
98
|
+
|
102
99
|
Object.class_eval do
|
103
|
-
|
100
|
+
|
104
101
|
class << self
|
105
102
|
|
106
103
|
def inherited_with_lumber_log4r(subclass)
|
@@ -115,7 +112,7 @@ module Lumber
|
|
115
112
|
Lumber.derive_lumber_logger(subclass)
|
116
113
|
end
|
117
114
|
end
|
118
|
-
|
115
|
+
|
119
116
|
alias_method_chain :inherited, :lumber_log4r
|
120
117
|
|
121
118
|
end
|
@@ -126,7 +123,6 @@ module Lumber
|
|
126
123
|
|
127
124
|
def self.add_lumber_logger(clazz, logger_name)
|
128
125
|
clazz.class_eval do
|
129
|
-
|
130
126
|
class_inheritable_accessor :logger
|
131
127
|
self.logger = Log4r::Logger.new(logger_name)
|
132
128
|
|
@@ -153,7 +149,7 @@ module Lumber
|
|
153
149
|
parent_logger_name = parent.logger.fullname rescue ''
|
154
150
|
parent_is_registered = @@registered_loggers.values.find {|v| parent_logger_name.index(v) == 0}
|
155
151
|
if parent_is_registered && parent.method_defined?(:logger=)
|
156
|
-
clazz.logger = Log4r::Logger.new("#{parent_logger_name}::#{clazz.name}")
|
152
|
+
clazz.logger = Log4r::Logger.new("#{parent_logger_name}::#{clazz.name.nil? ? 'anonymous' : clazz.name.split('::').last}")
|
157
153
|
break
|
158
154
|
end
|
159
155
|
parent = parent.superclass
|
data/test/logger_support_test.rb
CHANGED
@@ -2,8 +2,15 @@ require 'test_helper.rb'
|
|
2
2
|
|
3
3
|
class LoggerSupportTest < Test::Unit::TestCase
|
4
4
|
|
5
|
+
def setup
|
6
|
+
root = "#{File.dirname(__FILE__)}/.."
|
7
|
+
Lumber.init(:root => root,
|
8
|
+
:env => 'test',
|
9
|
+
:config_file => "#{root}/generators/lumber/templates/log4r.yml",
|
10
|
+
:log_file => "/tmp/lumber-test.log")
|
11
|
+
end
|
12
|
+
|
5
13
|
def teardown
|
6
|
-
Log4r::Logger::Repository.instance.loggers.clear
|
7
14
|
LoggerSupportTest.constants.grep(/^Foo/).each do |c|
|
8
15
|
LoggerSupportTest.send(:remove_const, c)
|
9
16
|
end
|
@@ -11,10 +18,10 @@ class LoggerSupportTest < Test::Unit::TestCase
|
|
11
18
|
|
12
19
|
should "create logger for chain" do
|
13
20
|
class Foo; include Lumber::LoggerSupport; end
|
14
|
-
|
15
|
-
assert_equal Log4r::Logger["rails::LoggerSupportTest"]
|
16
|
-
assert_equal Log4r::Logger["rails"]
|
17
|
-
assert_equal Log4r::Logger
|
21
|
+
class Bar < Foo; end;
|
22
|
+
assert_equal Foo.logger, Log4r::Logger["rails::LoggerSupportTest::Foo"]
|
23
|
+
assert_equal Bar.logger, Log4r::Logger["rails::LoggerSupportTest::Foo::Bar"]
|
24
|
+
assert_equal Bar.logger.parent, Log4r::Logger["rails::LoggerSupportTest::Foo"]
|
18
25
|
end
|
19
26
|
|
20
27
|
should "have a logger instance accessible from an instance method" do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 55
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
9
|
+
- 6
|
10
|
+
version: 0.9.6
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Matt Conway
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-10-12 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 0
|
30
32
|
version: "0"
|
@@ -38,6 +40,7 @@ dependencies:
|
|
38
40
|
requirements:
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
41
44
|
segments:
|
42
45
|
- 0
|
43
46
|
version: "0"
|
@@ -51,6 +54,7 @@ dependencies:
|
|
51
54
|
requirements:
|
52
55
|
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
54
58
|
segments:
|
55
59
|
- 0
|
56
60
|
version: "0"
|
@@ -96,6 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
100
|
requirements:
|
97
101
|
- - ">="
|
98
102
|
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
99
104
|
segments:
|
100
105
|
- 0
|
101
106
|
version: "0"
|
@@ -104,6 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
109
|
requirements:
|
105
110
|
- - ">="
|
106
111
|
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
107
113
|
segments:
|
108
114
|
- 0
|
109
115
|
version: "0"
|