lumber 0.10.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ Gemfile.lock
5
+ .config
6
+ .yardoc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,3 @@
1
+ <component name="ProjectDictionaryState">
2
+ <dictionary name="mconway" />
3
+ </component>
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ # - rbx-18mode
9
+ # - rbx-19mode
10
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lumber.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rdoc/task'
5
+ Rake::RDocTask.new do |rdoc|
6
+ if File.exist?('VERSION')
7
+ version = File.read('VERSION')
8
+ else
9
+ version = ""
10
+ end
11
+
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = "lumber #{version}"
14
+ rdoc.rdoc_files.include('README*')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ task :changelog do
19
+
20
+ changelog_file = 'CHANGELOG'
21
+ entries = ""
22
+
23
+ # Get a list of current tags
24
+ tags = `git tag -l`.split
25
+
26
+ # If we already have a changelog, make the last tag be the
27
+ # last one in the changelog, and the next one be the one
28
+ # following that in the tag list
29
+ if File.exist?(changelog_file)
30
+ entries = File.read(changelog_file)
31
+ head = entries.split.first
32
+ if head =~ /\d\.\d\.\d/
33
+ last_tag = "v#{head}"
34
+ idx = tags.index(last_tag)
35
+ current_tag = tags[idx + 1]
36
+ end
37
+ end
38
+
39
+ # Figure out last/current tags dn do some validation
40
+ last_tag ||= tags[-2]
41
+ current_tag ||= tags[-1]
42
+
43
+ if last_tag.nil? && current_tag.nil?
44
+ puts "Cannot generate a changelog without first tagging your repository"
45
+ puts "Tags should be in the form vN.N.N"
46
+ exit
47
+ end
48
+
49
+ if last_tag == current_tag
50
+ puts "Nothing to do for equal revisions: #{last_tag}..#{current_tag}"
51
+ exit
52
+ end
53
+
54
+
55
+ # Generate changelog from repo
56
+ log=`git log --pretty='format:%s <%h> [%cn]' #{last_tag}..#{current_tag}`
57
+
58
+ # Strip out maintenance entries
59
+ log = log.lines.to_a.delete_if {|l| l =~ /^Regenerated gemspec/ || l =~ /^Version bump/ || l =~ /^Updated changelog/ }
60
+
61
+ # Write out changelog file
62
+ File.open(changelog_file, 'w') do |out|
63
+ out.puts current_tag.gsub(/^v/, '')
64
+ out.puts "-----"
65
+ out.puts "\n"
66
+ out.puts log
67
+ out.puts "\n"
68
+ out.puts entries
69
+ end
70
+
71
+ # Commit and push
72
+ sh "git ci -m'Updated changelog' #{changelog_file}"
73
+ sh "git push"
74
+ end
data/lib/lumber/lumber.rb CHANGED
@@ -63,6 +63,10 @@ module Lumber
63
63
  self.register_inheritance_handler()
64
64
  end
65
65
 
66
+ def self.find_or_create_logger(fullname)
67
+ Log4r::Logger[fullname] || Log4r::Logger.new(fullname)
68
+ end
69
+
66
70
  # Makes :logger exist independently for subclasses and sets that logger
67
71
  # to one that inherits from base_class for each subclass as it is created.
68
72
  # This allows you to have a finer level of control over logging, for example,
@@ -90,7 +94,7 @@ module Lumber
90
94
  if clazz.respond_to? class_attribute_method
91
95
  clazz.class_eval do
92
96
  send class_attribute_method, :logger
93
- self.logger = Log4r::Logger.new(class_logger_fullname)
97
+ self.logger = Lumber.find_or_create_logger(class_logger_fullname)
94
98
  end
95
99
 
96
100
  break
@@ -143,7 +147,7 @@ module Lumber
143
147
  class_inheritable_accessor :logger
144
148
  end
145
149
 
146
- self.logger = Log4r::Logger.new(logger_name)
150
+ self.logger = Lumber.find_or_create_logger(logger_name)
147
151
 
148
152
  class << self
149
153
 
@@ -168,7 +172,8 @@ module Lumber
168
172
  parent_logger_name = parent.logger.fullname rescue ''
169
173
  parent_is_registered = @@registered_loggers.values.find {|v| parent_logger_name.index(v) == 0}
170
174
  if parent_is_registered && parent.method_defined?(:logger=)
171
- clazz.logger = Log4r::Logger.new("#{parent_logger_name}::#{clazz.name.nil? ? 'anonymous' : clazz.name.split('::').last}")
175
+ fullname = "#{parent_logger_name}::#{clazz.name.nil? ? 'anonymous' : clazz.name.split('::').last}"
176
+ clazz.logger = Lumber.find_or_create_logger(fullname)
172
177
  break
173
178
  end
174
179
  parent = parent.superclass
@@ -0,0 +1,3 @@
1
+ module Lumber
2
+ VERSION = "0.10.2"
3
+ end
data/lumber.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/lumber/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Matt Conway"]
6
+ gem.email = ["matt@conwaysplace.com"]
7
+ gem.description = %q{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.}
8
+ gem.summary = %q{Lumber integrates the log4r logging system within your application.}
9
+ gem.homepage = "http://github.com/wr0ngway/lumber"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "lumber"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Lumber::VERSION
17
+
18
+ gem.add_dependency("log4r", "~> 1.1.10")
19
+ gem.add_dependency("activesupport")
20
+
21
+ gem.add_development_dependency("rake")
22
+ gem.add_development_dependency("rspec")
23
+ gem.add_development_dependency("awesome_print")
24
+ # gem.add_development_dependency("simplecov")
25
+
26
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Lumber::LoggerSupport do
4
+
5
+ before(:each) do
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
+ after(:each) do
14
+ self.class.constants.grep(/^Foo/).each do |c|
15
+ self.send(:remove_const, c)
16
+ end
17
+ end
18
+
19
+ it "should create logger for chain" do
20
+ class Foo; include Lumber::LoggerSupport; end
21
+ class Bar < Foo; end;
22
+ Foo.logger.should == Log4r::Logger["rails::Foo"]
23
+ Bar.logger.should == Log4r::Logger["rails::Foo::Bar"]
24
+ Bar.logger.parent.should == Log4r::Logger["rails::Foo"]
25
+ end
26
+
27
+ it "should have a logger instance accessible from an instance method" do
28
+ class Foo; include Lumber::LoggerSupport; def member_method; logger.debug('hi'); end; end
29
+ logger = Log4r::Logger["rails::Foo"]
30
+ logger.should_receive(:debug).with('hi')
31
+ Foo.new.member_method
32
+ end
33
+
34
+ it "should have a logger instance accessible from a class method " do
35
+ class Foo; include Lumber::LoggerSupport; def self.class_method; logger.debug('hi'); end; end
36
+ logger = Log4r::Logger["rails::Foo"]
37
+ logger.should_receive(:debug).with('hi')
38
+ Foo.class_method
39
+ end
40
+
41
+ it "should allow configuration of levels from yml" do
42
+ yml = <<-EOF
43
+ log4r_config:
44
+ pre_config:
45
+ root:
46
+ level: 'DEBUG'
47
+ loggers:
48
+ - name: "rails::Foo"
49
+ level: WARN
50
+ outputters: []
51
+ EOF
52
+
53
+ cfg = Log4r::YamlConfigurator
54
+ cfg.load_yaml_string(yml)
55
+ logger = Log4r::Logger['rails::Foo']
56
+ sio = StringIO.new
57
+ logger.outputters = [Log4r::IOOutputter.new("sbout", sio)]
58
+ class Foo; include Lumber::LoggerSupport; end
59
+
60
+ Foo.logger.debug("noshow")
61
+ Foo.logger.warn("yesshow")
62
+ sio.string.should =~ /yesshow/
63
+ sio.string.should_not =~ /noshow/
64
+ end
65
+
66
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_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
+ describe Lumber do
15
+
16
+ before(:each) do
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
+ after(:each) do
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
+ clazz.should_not be_nil
33
+ clazz.respond_to?(:logger).should be_true
34
+ lgr = clazz.logger
35
+ lgr.should be_an_instance_of(Log4r::Logger)
36
+ logger_name.should == lgr.fullname
37
+ end
38
+
39
+ it "should not do anything if no loggers registered" do
40
+ defined?(Object.inherited_with_lumber_log4r).should be_true
41
+ defined?(Object.logger).should be_false
42
+ end
43
+
44
+ it "should allow registering logger for a class before the class is defined" do
45
+ defined?(Foo1).should be_false
46
+ Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
47
+ new_class('Foo1')
48
+ assert_valid_logger('Foo1', "root::foo1")
49
+ end
50
+
51
+ it "should not register new logger for subclasses of classes that delegate logger" do
52
+ defined?(Foo1).should be_false # ActionController::Base
53
+ defined?(Foo2).should be_false # ActionView::Base
54
+ defined?(Foo3).should be_false # 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
+ Foo2.new.logger.should == Foo1.logger
61
+ Foo3.new.logger.should == Foo1.logger
62
+ end
63
+
64
+ it "should no logger when parent is via delegate class" do
65
+ defined?(Foo1).should be_false
66
+ defined?(Foo2).should be_false
67
+ defined?(Foo3).should be_false
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
+ defined?(Foo3.logger).should be_false
74
+ end
75
+
76
+ it "should allow registering independent loggers for classes in a hierarchy" do
77
+ defined?(Foo1).should be_false
78
+ defined?(Foo2).should be_false
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
+ it "should prevent cattr_accessor for a class registered before the class is defined" do
88
+ defined?(Foo1).should be_false
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
+ defined?(Foo1.foo).should be_true
95
+ assert_valid_logger('Foo1', "root::foo1")
96
+ end
97
+
98
+ it "should allow registering logger for a nested class before the class is defined" do
99
+ defined?(Bar1::Foo1).should be_false
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
+ it "should allow registering logger for a class after the class is defined" do
106
+ defined?(Foo1).should be_false
107
+ new_class('Foo1')
108
+ defined?(Foo1).should be_true
109
+
110
+ Lumber.setup_logger_hierarchy("Foo1", "root::Foo1")
111
+ assert_valid_logger('Foo1', "root::Foo1")
112
+ end
113
+
114
+ it "should register loggers for subclasses of registered classes" do
115
+ defined?(Foo1).should be_false
116
+ defined?(Foo2).should be_false
117
+ defined?(Foo3).should be_false
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
+ defined?(Foo3.logger).should be_false
125
+ end
126
+
127
+ it "should register loggers for sub-subclasses of registered classes" do
128
+ defined?(Foo1).should be_false
129
+ defined?(Foo2).should be_false
130
+ defined?(Foo3).should be_false
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
+ it "should register loggers for sub-subclasses of registered classes even when middle class not a logger" do
141
+ defined?(Foo1).should be_false
142
+ defined?(Foo2).should be_false
143
+ defined?(Foo3).should be_false
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
+ # this will behave differently depending on the version of ActiveSupport being used. on ActiveSupport >= 3.2, we use class_attribute to define
150
+ # the logger method, which will cause subclasses to fall back to the parent class's logger if one isn't defined (Foo2.logger == Foo1.logger)
151
+ # if on ActiveSupport < 3.2, we use class_inheritable_accessor, which will leave the logger undefined in the subclass unless LoggerSupport
152
+ # is explicitly included
153
+ ((!defined?(Foo2.logger) || Foo2.logger.nil?) || (Foo2.logger == Foo1.logger)).should be_true
154
+ assert_valid_logger('Foo3', "root::Foo1::Foo3")
155
+ end
156
+
157
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,8 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --reverse
5
+ --timeout
6
+ 20
7
+ --loadby
8
+ mtime
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'ap'
3
+
4
+ require 'lumber'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,43 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-23 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: shoulda
16
- requirement: &70359307360500 !ruby/object:Gem::Requirement
15
+ name: log4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
17
49
  none: false
18
50
  requirements:
19
51
  - - ! '>='
@@ -21,44 +53,63 @@ dependencies:
21
53
  version: '0'
22
54
  type: :development
23
55
  prerelease: false
24
- version_requirements: *70359307360500
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
25
62
  - !ruby/object:Gem::Dependency
26
- name: log4r
27
- requirement: &70359307359560 !ruby/object:Gem::Requirement
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
28
65
  none: false
29
66
  requirements:
30
67
  - - ! '>='
31
68
  - !ruby/object:Gem::Version
32
69
  version: '0'
33
- type: :runtime
70
+ type: :development
34
71
  prerelease: false
35
- version_requirements: *70359307359560
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
36
78
  - !ruby/object:Gem::Dependency
37
- name: activesupport
38
- requirement: &70359307345720 !ruby/object:Gem::Requirement
79
+ name: awesome_print
80
+ requirement: !ruby/object:Gem::Requirement
39
81
  none: false
40
82
  requirements:
41
83
  - - ! '>='
42
84
  - !ruby/object:Gem::Version
43
85
  version: '0'
44
- type: :runtime
86
+ type: :development
45
87
  prerelease: false
46
- version_requirements: *70359307345720
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
47
94
  description: Lumber tries to make it easy to use the more robust log4r logging system
48
95
  within your rails application. To do this it sets up log4r configuration from a
49
96
  yml file, and provides utility methods for adding a :logger accessor to classes
50
97
  dynamicaly as they get created.
51
- email: matt@conwaysplace.com
98
+ email:
99
+ - matt@conwaysplace.com
52
100
  executables: []
53
101
  extensions: []
54
- extra_rdoc_files:
55
- - LICENSE
56
- - README.rdoc
57
- - TODO
102
+ extra_rdoc_files: []
58
103
  files:
104
+ - .document
105
+ - .gitignore
106
+ - .idea/dictionaries/mconway.xml
107
+ - .travis.yml
59
108
  - CHANGELOG
109
+ - Gemfile
60
110
  - LICENSE
61
111
  - README.rdoc
112
+ - Rakefile
62
113
  - TODO
63
114
  - VERSION
64
115
  - generators/lumber/USAGE
@@ -68,6 +119,12 @@ files:
68
119
  - lib/lumber/log4r.rb
69
120
  - lib/lumber/logger_support.rb
70
121
  - lib/lumber/lumber.rb
122
+ - lib/lumber/version.rb
123
+ - lumber.gemspec
124
+ - spec/logger_support_spec.rb
125
+ - spec/lumber_spec.rb
126
+ - spec/spec.opts
127
+ - spec/spec_helper.rb
71
128
  homepage: http://github.com/wr0ngway/lumber
72
129
  licenses: []
73
130
  post_install_message:
@@ -88,8 +145,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
145
  version: '0'
89
146
  requirements: []
90
147
  rubyforge_project:
91
- rubygems_version: 1.8.15
148
+ rubygems_version: 1.8.21
92
149
  signing_key:
93
150
  specification_version: 3
94
151
  summary: Lumber integrates the log4r logging system within your application.
95
- test_files: []
152
+ test_files:
153
+ - spec/logger_support_spec.rb
154
+ - spec/lumber_spec.rb
155
+ - spec/spec.opts
156
+ - spec/spec_helper.rb
157
+ has_rdoc: