lumber 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.9.6
2
+ -----
3
+
4
+ Made LoggerSupport module actually set up inherited loggers. <6758d73> [Kevin Menard]
5
+
1
6
  0.9.5
2
7
  -----
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.6
1
+ 0.10.0
data/lib/lumber/lumber.rb CHANGED
@@ -10,8 +10,15 @@ rescue LoadError
10
10
  require "active_support/core_ext/object/duplicable"
11
11
  end
12
12
 
13
- require "active_support/core_ext/class"
14
- require "active_support/core_ext/module"
13
+ begin
14
+ # attempt to explicitly load ActiveSupport::Deprecation for rails 3.2 (needed for active_support/core_ext/module)
15
+ # this doesn't appear to be necessary for earlier versions of rails (and may raise a LoadError)
16
+ require "active_support/deprecation"
17
+ ensure
18
+ require "active_support/core_ext/class"
19
+ require "active_support/core_ext/module"
20
+ end
21
+
15
22
 
16
23
  module Lumber
17
24
 
@@ -77,10 +84,16 @@ module Lumber
77
84
  begin
78
85
  clazz = class_name.constantize
79
86
 
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)
87
+ # ActiveSupport 3.2 introduced class_attribute, which is supposed to be used instead of class_inheritable_accessor if available
88
+ [:class_attribute, :class_inheritable_accessor].each do |class_attribute_method|
89
+
90
+ if clazz.respond_to? class_attribute_method
91
+ clazz.class_eval do
92
+ send class_attribute_method, :logger
93
+ self.logger = Log4r::Logger.new(class_logger_fullname)
94
+ end
95
+
96
+ break
84
97
  end
85
98
  end
86
99
 
@@ -123,7 +136,13 @@ module Lumber
123
136
 
124
137
  def self.add_lumber_logger(clazz, logger_name)
125
138
  clazz.class_eval do
126
- class_inheritable_accessor :logger
139
+ # ActiveSupport 3.2 introduced class_attribute, which is supposed to be used instead of class_inheritable_accessor if available
140
+ if respond_to? :class_attribute
141
+ class_attribute :logger
142
+ else
143
+ class_inheritable_accessor :logger
144
+ end
145
+
127
146
  self.logger = Log4r::Logger.new(logger_name)
128
147
 
129
148
  class << self
metadata CHANGED
@@ -1,76 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lumber
3
- version: !ruby/object:Gem::Version
4
- hash: 55
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 9
9
- - 6
10
- version: 0.9.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Matt Conway
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-12 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: shoulda
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70359307360500 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: log4r
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70359307360500
25
+ - !ruby/object:Gem::Dependency
26
+ name: log4r
27
+ requirement: &70359307359560 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: activesupport
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70359307359560
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ requirement: &70359307345720 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :runtime
62
- version_requirements: *id003
63
- description: Lumber tries to make it easy to use the more robust log4r logging system within your rails application. To do this it sets up log4r configuration from a yml file, and provides utility methods for adding a :logger accessor to classes dynamicaly as they get created.
45
+ prerelease: false
46
+ version_requirements: *70359307345720
47
+ description: Lumber tries to make it easy to use the more robust log4r logging system
48
+ within your rails application. To do this it sets up log4r configuration from a
49
+ yml file, and provides utility methods for adding a :logger accessor to classes
50
+ dynamicaly as they get created.
64
51
  email: matt@conwaysplace.com
65
52
  executables: []
66
-
67
53
  extensions: []
68
-
69
- extra_rdoc_files:
54
+ extra_rdoc_files:
70
55
  - LICENSE
71
56
  - README.rdoc
72
57
  - TODO
73
- files:
58
+ files:
74
59
  - CHANGELOG
75
60
  - LICENSE
76
61
  - README.rdoc
@@ -83,44 +68,28 @@ files:
83
68
  - lib/lumber/log4r.rb
84
69
  - lib/lumber/logger_support.rb
85
70
  - lib/lumber/lumber.rb
86
- - test/logger_support_test.rb
87
- - test/lumber_test.rb
88
- - test/test_helper.rb
89
- has_rdoc: true
90
71
  homepage: http://github.com/wr0ngway/lumber
91
72
  licenses: []
92
-
93
73
  post_install_message:
94
- rdoc_options:
95
- - --charset=UTF-8
96
- require_paths:
74
+ rdoc_options: []
75
+ require_paths:
97
76
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
99
78
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
84
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
116
89
  requirements: []
117
-
118
90
  rubyforge_project:
119
- rubygems_version: 1.3.7
91
+ rubygems_version: 1.8.15
120
92
  signing_key:
121
93
  specification_version: 3
122
94
  summary: Lumber integrates the log4r logging system within your application.
123
- test_files:
124
- - test/logger_support_test.rb
125
- - test/lumber_test.rb
126
- - test/test_helper.rb
95
+ test_files: []
@@ -1,43 +0,0 @@
1
- require 'test_helper.rb'
2
-
3
- class LoggerSupportTest < Test::Unit::TestCase
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
-
13
- def teardown
14
- LoggerSupportTest.constants.grep(/^Foo/).each do |c|
15
- LoggerSupportTest.send(:remove_const, c)
16
- end
17
- end
18
-
19
- should "create logger for chain" do
20
- class Foo; include Lumber::LoggerSupport; end
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"]
25
- end
26
-
27
- should "have a logger instance accessible from an instance method" do
28
- logger = stub_everything()
29
- Log4r::Logger.stubs(:new).returns(logger)
30
- class Foo; include Lumber::LoggerSupport; def member_method; logger.debug('hi'); end; end
31
- logger.expects(:debug).with('hi')
32
- Foo.new.member_method
33
- end
34
-
35
- should "have a logger instance accessible from a class method " do
36
- logger = stub_everything()
37
- Log4r::Logger.stubs(:new).returns(logger)
38
- class Foo; include Lumber::LoggerSupport; def self.class_method; logger.debug('hi'); end; end
39
- logger.expects(:debug).with('hi')
40
- Foo.class_method
41
- end
42
-
43
- end
data/test/lumber_test.rb DELETED
@@ -1,153 +0,0 @@
1
- require 'test_helper'
2
- require 'delegate'
3
-
4
- def new_class(class_name, super_class=nil, super_module=nil)
5
- s = "class #{class_name}"
6
- s << " < #{super_class}" if super_class
7
- s << "; end"
8
-
9
- s = "module #{super_module}; #{s}; end" if super_module
10
-
11
- eval s
12
- end
13
-
14
- class LumberTest < Test::Unit::TestCase
15
-
16
- def setup
17
- root = "#{File.dirname(__FILE__)}/.."
18
- Lumber.init(:root => root,
19
- :env => 'test',
20
- :config_file => "#{root}/generators/lumber/templates/log4r.yml",
21
- :log_file => "/tmp/lumber-test.log")
22
- end
23
-
24
- def teardown
25
- Object.constants.grep(/^Foo/).each do |c|
26
- Object.send(:remove_const, c)
27
- end
28
- end
29
-
30
- def assert_valid_logger(class_name, logger_name)
31
- clazz = eval class_name
32
- assert clazz
33
- assert clazz.respond_to?(:logger)
34
- lgr = clazz.logger
35
- assert lgr.instance_of?(Log4r::Logger)
36
- assert_equal logger_name, lgr.fullname
37
- end
38
-
39
- should "not do anything if no loggers registered" do
40
- assert defined?(Object.inherited_with_lumber_log4r)
41
- assert ! defined?(Object.logger)
42
- end
43
-
44
- should "allow registering logger for a class before the class is defined" do
45
- assert !defined?(Foo1)
46
- Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
47
- new_class('Foo1')
48
- assert_valid_logger('Foo1', "root::foo1")
49
- end
50
-
51
- should "not register new logger for subclasses of classes that delegate logger" do
52
- assert !defined?(Foo1) # ActionController::Base
53
- assert !defined?(Foo2) # ActionView::Base
54
- assert !defined?(Foo3) # Subclass of ActionView::Base
55
- Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
56
- eval "class ::Foo1; end"
57
- eval "class ::Foo2; delegate :logger, :to => Foo1; end"
58
- eval "class ::Foo3 < Foo2; end"
59
- assert_valid_logger('Foo1', "root::foo1")
60
- assert Foo2.new.logger == Foo1.logger
61
- assert Foo3.new.logger == Foo1.logger
62
- end
63
-
64
- should "no logger when parent is via delegate class" do
65
- assert !defined?(Foo1)
66
- assert !defined?(Foo2)
67
- assert !defined?(Foo3)
68
- Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
69
- eval "class ::Foo1; end"
70
- eval "class ::Foo2 < DelegateClass(Foo1); end"
71
- eval "class ::Foo3 < Foo2; end"
72
- assert_valid_logger('Foo1', "root::foo1")
73
- assert ! defined?(Foo3.logger)
74
- end
75
-
76
- should "allow registering independent loggers for classes in a hierarchy" do
77
- assert !defined?(Foo1)
78
- assert !defined?(Foo2)
79
- Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
80
- Lumber.setup_logger_hierarchy("Foo2", "root::foo2")
81
- new_class('Foo1')
82
- new_class('Foo2', 'Foo1')
83
- assert_valid_logger('Foo1', "root::foo1")
84
- assert_valid_logger('Foo2', "root::foo2")
85
- end
86
-
87
- should "prevent cattr_accessor for a class registered before the class is defined" do
88
- assert !defined?(Foo1)
89
- Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
90
- new_class('Foo1')
91
- Foo1.class_eval do
92
- cattr_accessor :logger, :foo
93
- end
94
- assert defined?(Foo1.foo)
95
- assert_valid_logger('Foo1', "root::foo1")
96
- end
97
-
98
- should "allow registering logger for a nested class before the class is defined" do
99
- assert !defined?(Bar1::Foo1)
100
- Lumber.setup_logger_hierarchy("Bar1::Foo1", "root::foo1")
101
- new_class('Foo1', nil, 'Bar1')
102
- assert_valid_logger('Bar1::Foo1', "root::foo1")
103
- end
104
-
105
- should "allow registering logger for a class after the class is defined" do
106
- assert !defined?(Foo1)
107
- new_class('Foo1')
108
- assert defined?(Foo1)
109
-
110
- Lumber.setup_logger_hierarchy("Foo1", "root::Foo1")
111
- assert_valid_logger('Foo1', "root::Foo1")
112
- end
113
-
114
- should "register loggers for subclasses of registered classes" do
115
- assert !defined?(Foo1)
116
- assert !defined?(Foo2)
117
- assert !defined?(Foo3)
118
- Lumber.setup_logger_hierarchy("Foo1", "root::Foo1")
119
- new_class('Foo1')
120
- new_class('Foo2', 'Foo1')
121
- new_class('Foo3')
122
- assert_valid_logger('Foo1', "root::Foo1")
123
- assert_valid_logger('Foo2', "root::Foo1::Foo2")
124
- assert ! defined?(Foo3.logger)
125
- end
126
-
127
- should "register loggers for sub-subclasses of registered classes" do
128
- assert !defined?(Foo1)
129
- assert !defined?(Foo2)
130
- assert !defined?(Foo3)
131
- Lumber.setup_logger_hierarchy("Foo1", "root::Foo1")
132
- new_class('Foo1')
133
- new_class('Foo2', 'Foo1')
134
- new_class('Foo3', 'Foo2')
135
- assert_valid_logger('Foo1', "root::Foo1")
136
- assert_valid_logger('Foo2', "root::Foo1::Foo2")
137
- assert_valid_logger('Foo3', "root::Foo1::Foo2::Foo3")
138
- end
139
-
140
- should "register loggers for sub-subclasses of registered classes even when middle class not a logger" do
141
- assert !defined?(Foo1)
142
- assert !defined?(Foo2)
143
- assert !defined?(Foo3)
144
- new_class('Foo1')
145
- new_class('Foo2', 'Foo1')
146
- Lumber.setup_logger_hierarchy("Foo1", "root::Foo1")
147
- new_class('Foo3', 'Foo2')
148
- assert_valid_logger('Foo1', "root::Foo1")
149
- assert !defined?(Foo2.logger) || Foo2.logger.nil?
150
- assert_valid_logger('Foo3', "root::Foo1::Foo3")
151
- end
152
-
153
- end
data/test/test_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha'
5
-
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- $LOAD_PATH.unshift(File.dirname(__FILE__))
8
- require 'lumber'
9
-
10
- class Test::Unit::TestCase
11
- end