log4r-exceptionable 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/lib/log4r-exceptionable/rack_failure_handler.rb +5 -2
- data/lib/log4r-exceptionable/resque_failure_handler.rb +6 -3
- data/lib/log4r-exceptionable/version.rb +1 -1
- data/spec/configuration_spec.rb +9 -3
- data/spec/rack_failure_handler_spec.rb +8 -9
- data/spec/resque_failure_handler_spec.rb +5 -6
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -40,10 +40,14 @@ module Log4rExceptionable
|
|
40
40
|
original_mdc = mdc.get_context
|
41
41
|
|
42
42
|
begin
|
43
|
+
message = "#{exception.class}: #{exception.message}"
|
44
|
+
|
43
45
|
mdc.put('rack_exception', exception.class.name)
|
44
46
|
trace = Array(exception.backtrace)
|
45
47
|
if trace.size > 0
|
46
|
-
|
48
|
+
message << "\n"
|
49
|
+
message << trace.join("\n")
|
50
|
+
|
47
51
|
file, line = trace[0].split(":")
|
48
52
|
mdc.put('rack_exception_file', file)
|
49
53
|
mdc.put('rack_exception_line', line)
|
@@ -67,7 +71,6 @@ module Log4rExceptionable
|
|
67
71
|
error_logger = Log4rExceptionable::Configuration.rack_failure_logger
|
68
72
|
end
|
69
73
|
|
70
|
-
message = "#{exception.class}: #{exception.message}"
|
71
74
|
error_logger.error(message)
|
72
75
|
ensure
|
73
76
|
# Since this is somewhat of a global map, clean the keys
|
@@ -12,10 +12,14 @@ module Log4rExceptionable
|
|
12
12
|
original_mdc = mdc.get_context
|
13
13
|
|
14
14
|
begin
|
15
|
-
|
15
|
+
message = "#{exception.class}: #{exception.message}"
|
16
|
+
|
17
|
+
mdc.put('resque_exception', exception.class.name)
|
16
18
|
trace = Array(exception.backtrace)
|
17
19
|
if trace.size > 0
|
18
|
-
|
20
|
+
message << "\n"
|
21
|
+
message << trace.join("\n")
|
22
|
+
|
19
23
|
file, line = trace[0].split(":")
|
20
24
|
mdc.put('resque_exception_file', file)
|
21
25
|
mdc.put('resque_exception_line', line)
|
@@ -33,7 +37,6 @@ module Log4rExceptionable
|
|
33
37
|
error_logger = Log4rExceptionable::Configuration.resque_failure_logger
|
34
38
|
end
|
35
39
|
|
36
|
-
message = "#{exception.class}: #{exception.message}"
|
37
40
|
error_logger.error(message)
|
38
41
|
ensure
|
39
42
|
# Since this is somewhat of a global map, clean the keys
|
data/spec/configuration_spec.rb
CHANGED
@@ -4,6 +4,11 @@ describe Log4rExceptionable::Configuration do
|
|
4
4
|
|
5
5
|
context "configure" do
|
6
6
|
|
7
|
+
before(:each) do
|
8
|
+
Log4rExceptionable::Configuration.rack_failure_logger = nil
|
9
|
+
Log4rExceptionable::Configuration.resque_failure_logger = nil
|
10
|
+
end
|
11
|
+
|
7
12
|
it "should raise if no logger in config" do
|
8
13
|
lambda {
|
9
14
|
Log4rExceptionable::Configuration.configure do |config|
|
@@ -11,14 +16,15 @@ describe Log4rExceptionable::Configuration do
|
|
11
16
|
}.should raise_error("log4r-exceptionable requires a rack_failure_logger or resque_failure_logger")
|
12
17
|
end
|
13
18
|
|
14
|
-
it "should not raise if config
|
19
|
+
it "should not raise if config has a rack logger" do
|
15
20
|
lambda {
|
16
21
|
Log4rExceptionable::Configuration.configure do |config|
|
17
22
|
config.rack_failure_logger = 'mylogger'
|
18
23
|
end
|
19
24
|
}.should_not raise_exception
|
20
|
-
|
21
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not raise if config has a resque logger" do
|
22
28
|
lambda {
|
23
29
|
Log4rExceptionable::Configuration.configure do |config|
|
24
30
|
config.resque_failure_logger = 'mylogger'
|
@@ -65,9 +65,8 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
65
65
|
|
66
66
|
it "triggers failure handler" do
|
67
67
|
Log4r::Logger['racklogger'].should_receive(:error) do |msg|
|
68
|
-
msg.should
|
69
|
-
|
70
|
-
Log4r::MDC.get('rack_exception_backtrace').lines.to_a.size.should > 1
|
68
|
+
msg.should =~ /^RuntimeError: I failed/
|
69
|
+
msg.should =~ /rack_failure_handler_spec.rb/
|
71
70
|
Log4r::MDC.get('rack_exception_line').should =~ /\d+/
|
72
71
|
Log4r::MDC.get('rack_exception_file').should =~ /rack_failure_handler_spec.rb/
|
73
72
|
Log4r::MDC.get('rack_env_PATH_INFO').should == '"/error"'
|
@@ -81,7 +80,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
81
80
|
it "uses default logger if controller logger is nil" do
|
82
81
|
|
83
82
|
Log4r::Logger['racklogger'].should_receive(:error) do |msg|
|
84
|
-
msg.should
|
83
|
+
msg.should =~ /^RuntimeError: I failed/
|
85
84
|
end
|
86
85
|
|
87
86
|
lambda {
|
@@ -92,7 +91,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
92
91
|
it "uses default logger if controller logger is not log4r" do
|
93
92
|
|
94
93
|
Log4r::Logger['racklogger'].should_receive(:error) do |msg|
|
95
|
-
msg.should
|
94
|
+
msg.should =~ /^RuntimeError: I failed/
|
96
95
|
end
|
97
96
|
|
98
97
|
lambda {
|
@@ -104,7 +103,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
104
103
|
Log4r::Logger.new('ControllerLogger')
|
105
104
|
Log4r::Logger['racklogger'].should_not_receive(:error)
|
106
105
|
Log4r::Logger['ControllerLogger'].should_receive(:error) do |msg|
|
107
|
-
msg.should
|
106
|
+
msg.should =~ /^RuntimeError: I failed/
|
108
107
|
end
|
109
108
|
|
110
109
|
lambda {
|
@@ -115,7 +114,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
115
114
|
it "uses default logger if rack logger is nil" do
|
116
115
|
|
117
116
|
Log4r::Logger['racklogger'].should_receive(:error) do |msg|
|
118
|
-
msg.should
|
117
|
+
msg.should =~ /^RuntimeError: I failed/
|
119
118
|
end
|
120
119
|
|
121
120
|
lambda {
|
@@ -126,7 +125,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
126
125
|
it "uses default logger if rack logger is not log4r" do
|
127
126
|
|
128
127
|
Log4r::Logger['racklogger'].should_receive(:error) do |msg|
|
129
|
-
msg.should
|
128
|
+
msg.should =~ /^RuntimeError: I failed/
|
130
129
|
end
|
131
130
|
|
132
131
|
lambda {
|
@@ -138,7 +137,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
138
137
|
Log4r::Logger.new('RackLogger')
|
139
138
|
Log4r::Logger['racklogger'].should_not_receive(:error)
|
140
139
|
Log4r::Logger['RackLogger'].should_receive(:error) do |msg|
|
141
|
-
msg.should
|
140
|
+
msg.should =~ /^RuntimeError: I failed/
|
142
141
|
end
|
143
142
|
|
144
143
|
lambda {
|
@@ -52,9 +52,8 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
52
52
|
it "triggers failure handler" do
|
53
53
|
|
54
54
|
Log4r::Logger['resquelogger'].should_receive(:error) do |msg|
|
55
|
-
msg.should
|
56
|
-
|
57
|
-
Log4r::MDC.get('resque_exception_backtrace').lines.to_a.size.should > 1
|
55
|
+
msg.should =~ /^RuntimeError: I failed/
|
56
|
+
msg.should =~ /resque_failure_handler_spec.rb/
|
58
57
|
Log4r::MDC.get('resque_exception_line').should =~ /\d+/
|
59
58
|
Log4r::MDC.get('resque_exception_file').should =~ /resque_failure_handler_spec.rb/
|
60
59
|
Log4r::MDC.get('resque_worker').should == ""
|
@@ -69,7 +68,7 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
69
68
|
it "uses default logger if job logger is nil" do
|
70
69
|
|
71
70
|
Log4r::Logger['resquelogger'].should_receive(:error) do |msg|
|
72
|
-
msg.should
|
71
|
+
msg.should =~ /^RuntimeError: I failed/
|
73
72
|
Log4r::MDC.get('resque_class').should == "SomeJobWithNilLogger"
|
74
73
|
end
|
75
74
|
|
@@ -79,7 +78,7 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
79
78
|
it "uses default logger if job logger is not log4r" do
|
80
79
|
|
81
80
|
Log4r::Logger['resquelogger'].should_receive(:error) do |msg|
|
82
|
-
msg.should
|
81
|
+
msg.should =~ /^RuntimeError: I failed/
|
83
82
|
Log4r::MDC.get('resque_class').should == "SomeJobWithOtherLogger"
|
84
83
|
end
|
85
84
|
|
@@ -90,7 +89,7 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
90
89
|
Log4r::Logger.new('SomeJobWithLogger')
|
91
90
|
Log4r::Logger['resquelogger'].should_not_receive(:error)
|
92
91
|
Log4r::Logger['SomeJobWithLogger'].should_receive(:error) do |msg|
|
93
|
-
msg.should
|
92
|
+
msg.should =~ /^RuntimeError: I failed/
|
94
93
|
Log4r::MDC.get('resque_class').should == "SomeJobWithLogger"
|
95
94
|
end
|
96
95
|
|