lumber 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c21e09e63cdd07d385285de3a1cff95010142484
4
- data.tar.gz: 0d988057d2cd29655df47bd152ddcb895b210e7b
3
+ metadata.gz: 9045f2bfc4c8673b4b70cbe7d664defdcfd11343
4
+ data.tar.gz: 4a7dbe6eadb815f6418d962b27486813d5fdde47
5
5
  SHA512:
6
- metadata.gz: 68b77ee858bade7f46862d63fa17a822b2f01f1bf9cc58aecb940da7dcae0ddbe53d2f39ed2ce2c80817a94a1b7a2c95418c84d1726c4a229e0c5ae79b353974
7
- data.tar.gz: 82b265689f2115815cff45fabfd9d41eb03b35bcbf077877478ce2ef4d2a5aff4074f985d2fc7c20b80412066f806201bd5aa7514c269d3eb9d301da7170590d
6
+ metadata.gz: 6c9a7e416c58fc6a5487e905678b363376aea45e9115b83735f8a62be687b36253e4f07669b87321a79b29e1523a8ee18bff1acbcaf5e3ea2a1f47a45d1058fe
7
+ data.tar.gz: 367cea68835d61fc011c096f974b2f855f961a09f31ab80b45eda50037c583f5cdc1021fe50b22efbebd0b985ca164dd051958620411b4d514337cc4b5b5fd11
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.1
5
6
  - jruby-19mode # JRuby in 1.9 mode
6
7
  - rbx
7
8
  before_script:
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 1.2.0 (03/03/2014)
2
+ ------------------
3
+
4
+ Remove need for PreventRailsOverride by ensuring that lumber gets added after class is defined, and add lumber logger at singleton level Add a rails integration test to make sure common use case of lumber in rails is correct <d2364f5> [Matt Conway]
5
+ add mri 2.1.0 to test targets <1acd50d> [Matt Conway]
6
+ fix travis (ruby with psych on travis seems to not like leading whitespace for inline yml strings) <c635e98> [Matt Conway]
7
+ test against 2.1.1 instead of 2.1.0 <2dcf586> [Matt Conway]
8
+
1
9
  1.1.3 (12/20/2013)
2
10
  ------------------
3
11
 
data/lib/lumber.rb CHANGED
@@ -5,7 +5,6 @@ require "monitor"
5
5
  require "lumber/lumber"
6
6
  require "lumber/inheritance_registry"
7
7
  require "lumber/logger_support"
8
- require "lumber/prevent_rails_override"
9
8
  require "lumber/log4r"
10
9
  require "lumber/level_util"
11
10
  require "lumber/json_formatter"
@@ -67,7 +67,6 @@ module Lumber
67
67
  # is loaded after registering logger inheritance
68
68
  if Lumber::InheritanceRegistry[subclass.name]
69
69
  subclass.send(:include, Lumber::LoggerSupport)
70
- subclass.send(:include, Lumber::PreventRailsOverride)
71
70
  end
72
71
  end
73
72
 
@@ -12,22 +12,30 @@ module Lumber
12
12
 
13
13
  delegate :logger, :to => "self.class"
14
14
 
15
- end
16
-
17
- module ClassMethods
18
-
19
-
20
- def logger
21
- # This should probably be synchronized, but don't want to
22
- # incur the performance hit on such a heavily used method.
23
- # I think the worst case is that it'll just get assigned
24
- # multiple times, but it'll get the same reference because
25
- # Lumber.logger has a lock
26
- @lumber_logger ||= Lumber.logger_for(self)
27
- end
28
-
29
- def logger=(logger)
30
- @lumber_logger = logger
15
+ # put logger on singleton class so it overrides any already there,
16
+ # and makes logger available from class, singleton_class and the
17
+ # instance (from the delegate call)
18
+ class << self
19
+
20
+ def lumber_logger
21
+ # This should probably be synchronized, but don't want to
22
+ # incur the performance hit on such a heavily used method.
23
+ # I think the worst case is that it'll just get assigned
24
+ # multiple times, but it'll get the same reference because
25
+ # Lumber.logger has a lock
26
+ @lumber_logger ||= Lumber.logger_for(self)
27
+ end
28
+
29
+ def lumber_logger=(logger)
30
+ @lumber_logger = logger
31
+ end
32
+
33
+ alias_method :logger, :lumber_logger
34
+
35
+ # prevent rails from setting logger (e.g. when initializing ActionController::Base)
36
+ def logger=(logger)
37
+ logger.debug "lumber preventing set of logger for #{self} to #{logger}, use #lumber_logger= if you really want it set"
38
+ end
31
39
  end
32
40
 
33
41
  end
data/lib/lumber/lumber.rb CHANGED
@@ -141,15 +141,18 @@ module Lumber
141
141
  #
142
142
  def setup_logger_hierarchy(class_name, class_logger_fullname)
143
143
  Lumber::InheritanceRegistry.register_inheritance_handler
144
- Lumber::InheritanceRegistry[class_name] = class_logger_fullname
145
144
 
146
145
  begin
147
146
  clazz = class_name.constantize
148
147
  clazz.send(:include, Lumber::LoggerSupport)
149
148
  rescue NameError
150
- # The class hasn't been defined yet. No problem, we've registered
151
- # the logger for when the class is created.
149
+ # The class hasn't been defined yet. No problem, we register
150
+ # the logger for when the class is created below
152
151
  end
152
+
153
+ # Don't register the class until after we see if it is already defined, that
154
+ # way LoggerSupport gets included _after_ class is defined and overrides logger
155
+ Lumber::InheritanceRegistry[class_name] = class_logger_fullname
153
156
  end
154
157
 
155
158
  # Helper to make it easier to log context through log4r.yml
@@ -26,14 +26,16 @@ module Lumber
26
26
  end
27
27
 
28
28
  initializer "lumber.set_logger_level", :after => :initialize_logger do |app|
29
- # Set the level on logger to workaround rails forcing level
30
- # to a ::Logger constant in the :initialize_logger initializer
31
- # https://github.com/rails/rails/issues/13421
32
- config_level = app.config.log_level
33
- level_str = config_level.to_s.upcase
34
- level = Log4r::LNAMES.index(level_str)
35
- raise "Invalid log level: #{config_level}" unless level
36
- app.config.logger.level = level
29
+ if app.config.lumber.enabled
30
+ # Set the level on logger to workaround rails forcing level
31
+ # to a ::Logger constant in the :initialize_logger initializer
32
+ # https://github.com/rails/rails/issues/13421
33
+ config_level = app.config.log_level
34
+ level_str = config_level.to_s.upcase
35
+ level = Log4r::LNAMES.index(level_str)
36
+ raise "Invalid log level: #{config_level}" unless level
37
+ app.config.logger.level = level
38
+ end
37
39
  end
38
40
 
39
41
  initializer "lumber.initialize_cache", :after => :initialize_cache do |app|
@@ -1,3 +1,3 @@
1
1
  module Lumber
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
data/lumber.gemspec CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |gem|
27
27
  gem.add_development_dependency("poltergeist")
28
28
  gem.add_development_dependency("awesome_print")
29
29
  gem.add_development_dependency("sinatra-contrib")
30
-
30
+ gem.add_development_dependency("rails", "~> 4.0.3")
31
31
  end
@@ -95,7 +95,6 @@ describe Lumber::InheritanceRegistry do
95
95
  InheritanceRegistry.register_inheritance_handler
96
96
  class Foo; end
97
97
  Foo.ancestors.should_not include(Lumber::LoggerSupport)
98
- Foo.ancestors.should_not include(Lumber::PreventRailsOverride)
99
98
  end
100
99
 
101
100
  it "adds logger support for classes that are registered" do
@@ -103,7 +102,6 @@ describe Lumber::InheritanceRegistry do
103
102
  InheritanceRegistry["Foo"] = "root::Foo"
104
103
  class Foo; end
105
104
  Foo.ancestors.should include(Lumber::LoggerSupport)
106
- Foo.ancestors.should include(Lumber::PreventRailsOverride)
107
105
  end
108
106
 
109
107
  end
@@ -21,7 +21,7 @@ describe Lumber::JsonFormatter do
21
21
  EOF
22
22
 
23
23
  cfg = Log4r::YamlConfigurator
24
- cfg.load_yaml_string(yml)
24
+ cfg.load_yaml_string(clean_indent(yml))
25
25
  outputter = Log4r::Outputter['stdout']
26
26
  outputter.formatter.should_not be_nil
27
27
  outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
@@ -47,7 +47,7 @@ describe Lumber::JsonFormatter do
47
47
  EOF
48
48
 
49
49
  cfg = Log4r::YamlConfigurator
50
- cfg.load_yaml_string(yml)
50
+ cfg.load_yaml_string(clean_indent(yml))
51
51
  outputter = Log4r::Outputter['stdout']
52
52
  outputter.formatter.should_not be_nil
53
53
  outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
@@ -74,7 +74,7 @@ describe Lumber::JsonFormatter do
74
74
  EOF
75
75
  yml.should include('#{1+1}')
76
76
  cfg = Log4r::YamlConfigurator
77
- cfg.load_yaml_string(yml)
77
+ cfg.load_yaml_string(clean_indent(yml))
78
78
  outputter = Log4r::Outputter['stdout']
79
79
  outputter.formatter.should_not be_nil
80
80
  outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
@@ -98,7 +98,7 @@ describe Lumber::JsonFormatter do
98
98
  date_pattern: "%M"
99
99
  EOF
100
100
  cfg = Log4r::YamlConfigurator
101
- cfg.load_yaml_string(yml)
101
+ cfg.load_yaml_string(clean_indent(yml))
102
102
  outputter = Log4r::Outputter['stdout']
103
103
  outputter.formatter.should_not be_nil
104
104
  outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
@@ -53,7 +53,7 @@ describe Lumber::LoggerSupport do
53
53
  EOF
54
54
 
55
55
  cfg = Log4r::YamlConfigurator
56
- cfg.load_yaml_string(yml)
56
+ cfg.load_yaml_string(clean_indent(yml))
57
57
  logger = Lumber.find_or_create_logger("rails::Foo")
58
58
  sio = StringIO.new
59
59
  logger.outputters = [Log4r::IOOutputter.new("sbout", sio)]
@@ -0,0 +1,13 @@
1
+ Bundler.with_clean_env do
2
+
3
+ gem 'lumber', :path => File.expand_path("../..", __FILE__)
4
+ run "bundle install"
5
+
6
+ generate(:lumber)
7
+ environment 'config.lumber.enabled = true'
8
+ environment 'config.lumber.log_level = ""'
9
+
10
+ generate(:resource, "user", "name:string")
11
+ generate(:mailer, "user_mailer")
12
+
13
+ end
data/spec/lumber_spec.rb CHANGED
@@ -123,17 +123,6 @@ describe Lumber do
123
123
  assert_valid_logger('Foo2', "root::foo2")
124
124
  end
125
125
 
126
- it "should prevent cattr_accessor for a class registered before the class is defined" do
127
- defined?(Foo1).should be_false
128
- Lumber.setup_logger_hierarchy("Foo1", "root::foo1")
129
- new_class('Foo1')
130
- Foo1.class_eval do
131
- cattr_accessor :logger, :foo
132
- end
133
- defined?(Foo1.foo).should be_true
134
- assert_valid_logger('Foo1', "root::foo1")
135
- end
136
-
137
126
  it "should allow registering logger for a nested class before the class is defined" do
138
127
  defined?(Bar1::Foo1).should be_false
139
128
  Lumber.setup_logger_hierarchy("Bar1::Foo1", "root::foo1")
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'active_support/time'
3
+
4
+ describe "Rails Integration" do
5
+
6
+ class RailsRunner
7
+
8
+ def initialize(rails_root)
9
+ Bundler.with_clean_env do
10
+ @io = open("|#{rails_root}/bin/rails runner 'STDOUT.sync=STDERR.sync=true; loop { begin; puts eval gets.to_s; rescue => e; p e; end }'", "w+")
11
+ @pid = $?.pid
12
+ end
13
+ end
14
+
15
+ def execute(cmd)
16
+ @io.puts(cmd)
17
+ @io.gets.to_s.strip
18
+ end
19
+ end
20
+
21
+ before(:all) do
22
+ project_dir = File.expand_path("../..", __FILE__)
23
+ spec_dir = "#{project_dir}/spec"
24
+
25
+ @rails_root = "/tmp/lumber_test_rails_integration"
26
+ if ! File.exist?(@rails_root) || File.mtime(@rails_root) < 1.day.ago
27
+ FileUtils.rm_rf(@rails_root)
28
+ out = `cd #{project_dir} && bundle exec rails new #{@rails_root} -m #{spec_dir}/lumber_rails_template.rb`
29
+ fail(out) unless $?.success?
30
+ end
31
+
32
+ @runner = RailsRunner.new(@rails_root)
33
+ end
34
+
35
+ after(:all) do
36
+ @runner.execute('exit!')
37
+ #FileUtils.rm_rf(@rails_root)
38
+ end
39
+
40
+ it "has a rails logger" do
41
+ @runner.execute("Rails.logger.class").should == "Log4r::Logger"
42
+ @runner.execute("Rails.logger.fullname").should == "rails"
43
+ end
44
+
45
+ it "has a rails logger for models" do
46
+ @runner.execute("User.logger.class").should == "Log4r::Logger"
47
+ @runner.execute("User.logger.fullname").should == "rails::models::User"
48
+ end
49
+
50
+ it "has a rails logger for mailers" do
51
+ @runner.execute("UserMailer.logger.class").should == "Log4r::Logger"
52
+ @runner.execute("UserMailer.logger.fullname").should == "rails::mailers::UserMailer"
53
+ end
54
+
55
+ it "has a rails logger for controllers" do
56
+ @runner.execute("UsersController.logger.class").should == "Log4r::Logger"
57
+ @runner.execute("UsersController.logger.fullname").should == "rails::controllers::UsersController"
58
+ end
59
+
60
+ end
61
+
data/spec/spec_helper.rb CHANGED
@@ -26,6 +26,22 @@ require 'capybara/rspec'
26
26
  require 'capybara/poltergeist'
27
27
  Capybara.javascript_driver = :poltergeist
28
28
 
29
+ def clean_indent(str)
30
+ first_indent = nil
31
+ str.lines.collect do |line|
32
+ if line =~ /\S/ # line has at least one non-whitespace character
33
+ if first_indent.nil?
34
+ line =~ /^(\s*)/
35
+ first_indent = $1
36
+ end
37
+ line.slice!(0, first_indent.size)
38
+ line
39
+ else
40
+ ""
41
+ end
42
+ end.join()
43
+ end
44
+
29
45
  def new_class(class_name, super_class=nil, super_module=nil)
30
46
  s = "class #{class_name}"
31
47
  s << " < #{super_class}" if super_class
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-20 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: log4r
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: 4.0.3
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 4.0.3
153
167
  description: Lumber tries to make it easy to use the more robust log4r logging system
154
168
  within your rails application. To do this it sets up log4r configuration from a
155
169
  yml file, and provides utility methods for adding a :logger accessor to classes
@@ -180,7 +194,6 @@ files:
180
194
  - lib/lumber/log4r.rb
181
195
  - lib/lumber/logger_support.rb
182
196
  - lib/lumber/lumber.rb
183
- - lib/lumber/prevent_rails_override.rb
184
197
  - lib/lumber/railtie.rb
185
198
  - lib/lumber/server.rb
186
199
  - lib/lumber/server/public/lib/bootstrap/css/bootstrap-responsive.css
@@ -201,8 +214,9 @@ files:
201
214
  - spec/json_formatter_spec.rb
202
215
  - spec/level_util_spec.rb
203
216
  - spec/logger_support_spec.rb
217
+ - spec/lumber_rails_template.rb
204
218
  - spec/lumber_spec.rb
205
- - spec/prevent_rails_override_spec.rb
219
+ - spec/rails_integration_spec.rb
206
220
  - spec/server_spec.rb
207
221
  - spec/spec.opts
208
222
  - spec/spec_helper.rb
@@ -235,8 +249,9 @@ test_files:
235
249
  - spec/json_formatter_spec.rb
236
250
  - spec/level_util_spec.rb
237
251
  - spec/logger_support_spec.rb
252
+ - spec/lumber_rails_template.rb
238
253
  - spec/lumber_spec.rb
239
- - spec/prevent_rails_override_spec.rb
254
+ - spec/rails_integration_spec.rb
240
255
  - spec/server_spec.rb
241
256
  - spec/spec.opts
242
257
  - spec/spec_helper.rb
@@ -1,44 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- module Lumber
4
-
5
- # Include this module to add a logger accessible from both class and instance methods.
6
- # A logger hierarchy will be created if the class including this module is nested
7
- module PreventRailsOverride
8
- extend ActiveSupport::Concern
9
-
10
- included do
11
-
12
- class << self
13
- # Prevent rails from overwriting our logger
14
- def cattr_reader_with_lumber(*syms)
15
- without_logger = syms.reject {|s| s == :logger}
16
- cattr_reader_without_lumber(*without_logger)
17
- end
18
- alias_method_chain :cattr_reader, :lumber
19
-
20
- def cattr_writer_with_lumber(*syms)
21
- without_logger = syms.reject {|s| s == :logger}
22
- cattr_writer_without_lumber(*without_logger)
23
- end
24
- alias_method_chain :cattr_writer, :lumber
25
-
26
- def mattr_reader_with_lumber(*syms)
27
- without_logger = syms.reject {|s| s == :logger}
28
- mattr_reader_without_lumber(*without_logger)
29
- end
30
- alias_method_chain :mattr_reader, :lumber
31
-
32
- def mattr_writer_with_lumber(*syms)
33
- without_logger = syms.reject {|s| s == :logger}
34
- mattr_writer_without_lumber(*without_logger)
35
- end
36
- alias_method_chain :mattr_writer, :lumber
37
-
38
- end
39
-
40
- end
41
-
42
- end
43
-
44
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumber::PreventRailsOverride do
4
-
5
- it "should prevent cattr_accessor for :logger" do
6
- new_class('Foo1')
7
- Foo1.send(:include, Lumber::PreventRailsOverride)
8
- Foo1.class_eval do
9
- cattr_accessor :logger
10
- end
11
- Foo1.method_defined?(:logger).should be_false
12
- Foo1.method_defined?(:logger=).should be_false
13
- end
14
-
15
- it "should allow cattr_accessor for attrs other than :logger" do
16
- new_class('Foo1')
17
- Foo1.send(:include, Lumber::PreventRailsOverride)
18
- Foo1.class_eval do
19
- cattr_accessor :foo
20
- end
21
- Foo1.method_defined?(:foo).should be_true
22
- Foo1.method_defined?(:foo=).should be_true
23
- end
24
-
25
- it "should prevent mattr_accessor for :logger" do
26
- new_class('Foo1')
27
- Foo1.send(:include, Lumber::PreventRailsOverride)
28
- Foo1.class_eval do
29
- mattr_accessor :logger
30
- end
31
- Foo1.method_defined?(:logger).should be_false
32
- Foo1.method_defined?(:logger=).should be_false
33
- end
34
-
35
- it "should allow mattr_accessor for attrs other than :logger" do
36
- new_class('Foo1')
37
- Foo1.send(:include, Lumber::PreventRailsOverride)
38
- Foo1.class_eval do
39
- mattr_accessor :foo
40
- end
41
- Foo1.method_defined?(:foo).should be_true
42
- Foo1.method_defined?(:foo=).should be_true
43
- end
44
-
45
- end