lumber 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/lumber/level_util.rb +23 -6
- data/lib/lumber/server/views/levels.erb +7 -3
- data/lib/lumber/version.rb +1 -1
- data/spec/level_util_spec.rb +51 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/lumber/level_util.rb
CHANGED
@@ -51,9 +51,14 @@ module Lumber
|
|
51
51
|
else
|
52
52
|
backup_levels(levels.keys)
|
53
53
|
levels.each do |name, level|
|
54
|
-
logger = Lumber.find_or_create_logger(name)
|
55
54
|
level_val = Log4r::LNAMES.index(level)
|
56
|
-
|
55
|
+
outputter = Log4r::Outputter[name]
|
56
|
+
if outputter
|
57
|
+
outputter.level = level_val if level_val && outputter.level != level_val
|
58
|
+
else
|
59
|
+
logger = Lumber.find_or_create_logger(name)
|
60
|
+
logger.level = level_val if level_val && logger.level != level_val
|
61
|
+
end
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
@@ -81,6 +86,7 @@ module Lumber
|
|
81
86
|
protected
|
82
87
|
|
83
88
|
@original_levels = {}
|
89
|
+
@original_outputter_levels = {}
|
84
90
|
|
85
91
|
# Backs up original values of logger levels before we overwrite them
|
86
92
|
# This is better in local memory since we shouldn't reset loggers that we haven't set
|
@@ -88,9 +94,14 @@ module Lumber
|
|
88
94
|
def backup_levels(loggers)
|
89
95
|
synchronize do
|
90
96
|
loggers.each do |name|
|
91
|
-
|
92
|
-
|
93
|
-
|
97
|
+
outputter = Log4r::Outputter[name]
|
98
|
+
if outputter
|
99
|
+
@original_outputter_levels[name] ||= outputter.level
|
100
|
+
else
|
101
|
+
logger = Lumber.find_or_create_logger(name)
|
102
|
+
# only store the old level if we haven't overriden it's logger yet
|
103
|
+
@original_levels[name] ||= logger.level
|
104
|
+
end
|
94
105
|
end
|
95
106
|
end
|
96
107
|
end
|
@@ -98,9 +109,15 @@ module Lumber
|
|
98
109
|
# Restores original values of logger levels after expiration
|
99
110
|
def restore_levels
|
100
111
|
synchronize do
|
112
|
+
@original_outputter_levels.each do |name, level|
|
113
|
+
outputter = Log4r::Outputter[name]
|
114
|
+
outputter.level = level if outputter.level != level
|
115
|
+
end
|
116
|
+
@original_outputter_levels.clear
|
117
|
+
|
101
118
|
@original_levels.each do |name, level|
|
102
119
|
logger = Lumber.find_or_create_logger(name)
|
103
|
-
logger.level = level
|
120
|
+
logger.level = level if logger.level != level
|
104
121
|
end
|
105
122
|
@original_levels.clear
|
106
123
|
end
|
@@ -38,9 +38,13 @@
|
|
38
38
|
</table>
|
39
39
|
|
40
40
|
<script type="text/javascript" charset="utf-8">
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
<%
|
42
|
+
lnames = []
|
43
|
+
Log4r::Outputter.each {|name, outputter| lnames << name }
|
44
|
+
Log4r::Logger.each {|name, logger| lnames << name }
|
45
|
+
%>
|
46
|
+
var typeahead_logger_names = <%= lnames.sort.inspect %>;
|
47
|
+
var typeahead_logger_levels = <%= Log4r::LNAMES.sort.inspect %>;
|
44
48
|
|
45
49
|
jQuery(document).ready(function() {
|
46
50
|
$('input[name="levels[][name]"]').typeahead({source: typeahead_logger_names})
|
data/lib/lumber/version.rb
CHANGED
data/spec/level_util_spec.rb
CHANGED
@@ -45,7 +45,7 @@ describe Lumber::LevelUtil do
|
|
45
45
|
Log4r::Logger[@name].should == foo_logger
|
46
46
|
end
|
47
47
|
|
48
|
-
it "
|
48
|
+
it "activates level on logger" do
|
49
49
|
Lumber.find_or_create_logger(@name)
|
50
50
|
LevelUtil.set_levels({@name => "ERROR"})
|
51
51
|
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("DEBUG")
|
@@ -53,6 +53,20 @@ describe Lumber::LevelUtil do
|
|
53
53
|
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("ERROR")
|
54
54
|
end
|
55
55
|
|
56
|
+
it "activates level on outputter" do
|
57
|
+
logger = Lumber.find_or_create_logger(@name)
|
58
|
+
sio = StringIO.new
|
59
|
+
outputter = Log4r::IOOutputter.new("sbout", sio)
|
60
|
+
logger.outputters = [outputter]
|
61
|
+
|
62
|
+
LevelUtil.set_levels({"sbout" => "ERROR"})
|
63
|
+
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("DEBUG")
|
64
|
+
outputter.level.should == Log4r::LNAMES.index("DEBUG")
|
65
|
+
LevelUtil.activate_levels
|
66
|
+
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("DEBUG")
|
67
|
+
outputter.level.should == Log4r::LNAMES.index("ERROR")
|
68
|
+
end
|
69
|
+
|
56
70
|
it "restores levels when mapping expires" do
|
57
71
|
Lumber.find_or_create_logger(@name)
|
58
72
|
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("DEBUG")
|
@@ -66,6 +80,42 @@ describe Lumber::LevelUtil do
|
|
66
80
|
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("DEBUG")
|
67
81
|
end
|
68
82
|
|
83
|
+
it "restores levels on outputter when mapping expires" do
|
84
|
+
logger = Lumber.find_or_create_logger(@name)
|
85
|
+
sio = StringIO.new
|
86
|
+
outputter = Log4r::IOOutputter.new("sbout", sio)
|
87
|
+
logger.outputters = [outputter]
|
88
|
+
|
89
|
+
outputter.level.should == Log4r::LNAMES.index("DEBUG")
|
90
|
+
|
91
|
+
LevelUtil.set_levels({"sbout" => "ERROR"})
|
92
|
+
LevelUtil.activate_levels
|
93
|
+
outputter.level.should == Log4r::LNAMES.index("ERROR")
|
94
|
+
|
95
|
+
LevelUtil.set_levels({})
|
96
|
+
LevelUtil.activate_levels
|
97
|
+
outputter.level.should == Log4r::LNAMES.index("DEBUG")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "doesn't set levels if already set" do
|
101
|
+
logger = Lumber.find_or_create_logger(@name)
|
102
|
+
sio = StringIO.new
|
103
|
+
outputter = Log4r::IOOutputter.new("sbout", sio)
|
104
|
+
logger.outputters = [outputter]
|
105
|
+
|
106
|
+
outputter.level.should == Log4r::LNAMES.index("DEBUG")
|
107
|
+
Log4r::Logger[@name].level.should == Log4r::LNAMES.index("DEBUG")
|
108
|
+
|
109
|
+
outputter.should_not_receive(:level=)
|
110
|
+
Log4r::Logger[@name].should_not_receive(:level=)
|
111
|
+
|
112
|
+
LevelUtil.set_levels({"sbout" => "DEBUG", @name => "DEBUG"})
|
113
|
+
LevelUtil.activate_levels
|
114
|
+
|
115
|
+
LevelUtil.set_levels({})
|
116
|
+
LevelUtil.activate_levels
|
117
|
+
end
|
118
|
+
|
69
119
|
it "starts a monitor thread" do
|
70
120
|
LevelUtil.set_levels({@name => "DEBUG"})
|
71
121
|
LevelUtil.activate_levels
|
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.
|
4
|
+
version: 0.12.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: log4r
|