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 +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG +8 -0
- data/lib/lumber.rb +0 -1
- data/lib/lumber/inheritance_registry.rb +0 -1
- data/lib/lumber/logger_support.rb +24 -16
- data/lib/lumber/lumber.rb +6 -3
- data/lib/lumber/railtie.rb +10 -8
- data/lib/lumber/version.rb +1 -1
- data/lumber.gemspec +1 -1
- data/spec/inheritance_registry_spec.rb +0 -2
- data/spec/json_formatter_spec.rb +4 -4
- data/spec/logger_support_spec.rb +1 -1
- data/spec/lumber_rails_template.rb +13 -0
- data/spec/lumber_spec.rb +0 -11
- data/spec/rails_integration_spec.rb +61 -0
- data/spec/spec_helper.rb +16 -0
- metadata +20 -5
- data/lib/lumber/prevent_rails_override.rb +0 -44
- data/spec/prevent_rails_override_spec.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9045f2bfc4c8673b4b70cbe7d664defdcfd11343
|
4
|
+
data.tar.gz: 4a7dbe6eadb815f6418d962b27486813d5fdde47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c9a7e416c58fc6a5487e905678b363376aea45e9115b83735f8a62be687b36253e4f07669b87321a79b29e1523a8ee18bff1acbcaf5e3ea2a1f47a45d1058fe
|
7
|
+
data.tar.gz: 367cea68835d61fc011c096f974b2f855f961a09f31ab80b45eda50037c583f5cdc1021fe50b22efbebd0b985ca164dd051958620411b4d514337cc4b5b5fd11
|
data/.travis.yml
CHANGED
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
@@ -12,22 +12,30 @@ module Lumber
|
|
12
12
|
|
13
13
|
delegate :logger, :to => "self.class"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
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
|
data/lib/lumber/railtie.rb
CHANGED
@@ -26,14 +26,16 @@ module Lumber
|
|
26
26
|
end
|
27
27
|
|
28
28
|
initializer "lumber.set_logger_level", :after => :initialize_logger do |app|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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|
|
data/lib/lumber/version.rb
CHANGED
data/lumber.gemspec
CHANGED
@@ -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
|
data/spec/json_formatter_spec.rb
CHANGED
@@ -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
|
data/spec/logger_support_spec.rb
CHANGED
@@ -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.
|
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:
|
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/
|
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/
|
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
|