lumber 0.9.4 → 0.9.5

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.4
2
+ -----
3
+
4
+ rails3 support <096ad75> [Matt Conway]
5
+
1
6
  0.9.3
2
7
  -----
3
8
 
data/README.rdoc CHANGED
@@ -23,7 +23,14 @@ to config/environment.rb:
23
23
  # If you really want, you can make all classes have a logger
24
24
  # Lumber.setup_logger_hierarchy("Object", "root::object")
25
25
 
26
-
26
+ Additionally, you can also add loggers to individual classes by including the LumberLoggerSupport module
27
+ class Foo
28
+ include Lumber::LoggerSupport
29
+ end
30
+
31
+ and Foo.logger/Foo.new.logger will log to a logger named "rails::Foo". This creates a heirarchy of loggers for classes
32
+ nested within modules, so you can use the namespace to enable/disable loggers
33
+
27
34
  If you want to change the log level for a different environment, add a line like below to the config/environments/<env>.rb
28
35
 
29
36
  # Set info as the default log level for production
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -0,0 +1,26 @@
1
+ module Lumber
2
+
3
+ # Include this module to add a logger accessible from both class and instance methods.
4
+ # A logger heirarchy will be created if the class including this module is nested
5
+ module LoggerSupport
6
+
7
+ def self.included(receiver)
8
+ receiver.class_eval do
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
22
+ end
23
+
24
+ end
25
+
26
+ end
data/lib/lumber/lumber.rb CHANGED
@@ -13,6 +13,9 @@ require "active_support/core_ext/module"
13
13
 
14
14
  module Lumber
15
15
 
16
+ # name of top level logger (can't be root as you can't have outputters on root)
17
+ BASE_LOGGER= 'rails'
18
+
16
19
  # Initializes log4r system. Needs to happen in
17
20
  # config/environment.rb before Rails::Initializer.run
18
21
  #
@@ -45,7 +48,7 @@ module Lumber
45
48
  if defined?(RAILS_DEFAULT_LOGGER)
46
49
  Object.send(:remove_const, :RAILS_DEFAULT_LOGGER)
47
50
  end
48
- Object.const_set('RAILS_DEFAULT_LOGGER', Log4r::Logger['rails'])
51
+ Object.const_set('RAILS_DEFAULT_LOGGER', Log4r::Logger[BASE_LOGGER])
49
52
 
50
53
  @@registered_loggers = {}
51
54
  self.register_inheritance_handler()
data/lib/lumber.rb CHANGED
@@ -2,5 +2,6 @@ $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  # before config block
4
4
  require "lumber/lumber"
5
+ require "lumber/logger_support"
5
6
  require "lumber/log4r"
6
7
 
@@ -0,0 +1,36 @@
1
+ require 'test_helper.rb'
2
+
3
+ class LoggerSupportTest < Test::Unit::TestCase
4
+
5
+ def teardown
6
+ Log4r::Logger::Repository.instance.loggers.clear
7
+ LoggerSupportTest.constants.grep(/^Foo/).each do |c|
8
+ LoggerSupportTest.send(:remove_const, c)
9
+ end
10
+ end
11
+
12
+ should "create logger for chain" do
13
+ class Foo; include Lumber::LoggerSupport; end
14
+ assert_equal Log4r::Logger["rails::LoggerSupportTest::Foo"], Foo.logger
15
+ assert_equal Log4r::Logger["rails::LoggerSupportTest"], Foo.logger.parent
16
+ assert_equal Log4r::Logger["rails"], Foo.logger.parent.parent
17
+ assert_equal Log4r::Logger.root, Foo.logger.parent.parent.parent
18
+ end
19
+
20
+ should "have a logger instance accessible from an instance method" do
21
+ logger = stub_everything()
22
+ Log4r::Logger.stubs(:new).returns(logger)
23
+ class Foo; include Lumber::LoggerSupport; def member_method; logger.debug('hi'); end; end
24
+ logger.expects(:debug).with('hi')
25
+ Foo.new.member_method
26
+ end
27
+
28
+ should "have a logger instance accessible from a class method " do
29
+ logger = stub_everything()
30
+ Log4r::Logger.stubs(:new).returns(logger)
31
+ class Foo; include Lumber::LoggerSupport; def self.class_method; logger.debug('hi'); end; end
32
+ logger.expects(:debug).with('hi')
33
+ Foo.class_method
34
+ end
35
+
36
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'mocha'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 4
9
- version: 0.9.4
8
+ - 5
9
+ version: 0.9.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matt Conway
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-25 00:00:00 -04:00
17
+ date: 2010-07-01 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -77,7 +77,9 @@ files:
77
77
  - generators/lumber/templates/log4r.yml
78
78
  - lib/lumber.rb
79
79
  - lib/lumber/log4r.rb
80
+ - lib/lumber/logger_support.rb
80
81
  - lib/lumber/lumber.rb
82
+ - test/logger_support_test.rb
81
83
  - test/lumber_test.rb
82
84
  - test/test_helper.rb
83
85
  has_rdoc: true
@@ -113,5 +115,6 @@ signing_key:
113
115
  specification_version: 3
114
116
  summary: Lumber integrates the log4r logging system within your application.
115
117
  test_files:
118
+ - test/logger_support_test.rb
116
119
  - test/lumber_test.rb
117
120
  - test/test_helper.rb