log4r-exceptionable 0.5.3 → 0.5.4
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 +6 -0
- data/README.md +2 -2
- data/lib/log4r-exceptionable/rack_failure_handler.rb +3 -3
- data/lib/log4r-exceptionable/resque_failure_handler.rb +8 -6
- data/lib/log4r-exceptionable/version.rb +1 -1
- data/spec/rack_failure_handler_spec.rb +1 -1
- data/spec/resque_failure_handler_spec.rb +6 -6
- metadata +1 -1
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
log4r-exceptionable
|
2
|
+
===================
|
3
3
|
|
4
4
|
This gem provides failure handlers for [Resque][0] and [Rack][1] that logs all failures using [log4r][2]. It is expected that these logs will get sent elsewhere (e.g. [graylog][3]) by using log4r outputters (e.g. [log4r-gelf][4]). It adds contextual information to the log message using Log4r::MDC, which is useful if you are using log4r-gelf since it sends all of those to graylog as custom attributes.
|
5
5
|
|
@@ -44,7 +44,7 @@ module Log4rExceptionable
|
|
44
44
|
if env and env.size > 0
|
45
45
|
env.each do |k, v|
|
46
46
|
begin
|
47
|
-
mdc.put("rack_env_#{k}", v
|
47
|
+
mdc.put("rack_env_#{k}", v)
|
48
48
|
rescue
|
49
49
|
puts "Log4r Exceptionable could not extract a rack env item: " + e.message
|
50
50
|
end
|
@@ -55,8 +55,8 @@ module Log4rExceptionable
|
|
55
55
|
if controller && controller.respond_to?(:logger) && controller.logger.instance_of?(Log4r::Logger)
|
56
56
|
error_logger = controller.logger
|
57
57
|
begin
|
58
|
-
mdc.put("rack_controller_name", controller.controller_name
|
59
|
-
mdc.put("rack_action_name", controller.action_name
|
58
|
+
mdc.put("rack_controller_name", controller.controller_name)
|
59
|
+
mdc.put("rack_action_name", controller.action_name)
|
60
60
|
rescue => e
|
61
61
|
puts "Log4r Exceptionable could not extract controller names: " + e.message
|
62
62
|
end
|
@@ -12,17 +12,19 @@ module Log4rExceptionable
|
|
12
12
|
original_mdc = mdc.get_context
|
13
13
|
|
14
14
|
begin
|
15
|
-
|
15
|
+
|
16
16
|
data = payload.clone
|
17
|
-
|
18
|
-
|
19
|
-
mdc.put("
|
20
|
-
mdc.put("
|
17
|
+
payload_class_name = data.delete('class')
|
18
|
+
payload_class = Resque.constantize(payload_class_name) rescue payload_class_name
|
19
|
+
mdc.put("resque_worker", worker)
|
20
|
+
mdc.put("resque_queue", queue)
|
21
|
+
mdc.put("resque_class", payload_class)
|
22
|
+
mdc.put("resque_args", data.delete('args'))
|
21
23
|
|
22
24
|
# add in any extra payload data, in case resque plugins have
|
23
25
|
# added to it (e.g. resque-lifecycle)
|
24
26
|
data.each do |k, v|
|
25
|
-
mdc.put("resque_payload_#{k}", v
|
27
|
+
mdc.put("resque_payload_#{k}", v)
|
26
28
|
end
|
27
29
|
|
28
30
|
payload_class = Resque.constantize(payload['class']) rescue nil
|
@@ -74,7 +74,7 @@ describe Log4rExceptionable::RackFailureHandler do
|
|
74
74
|
msg.should be_instance_of RuntimeError
|
75
75
|
msg.message.should == "I failed"
|
76
76
|
msg.backtrace.first.should =~ /rack_failure_handler_spec.rb/
|
77
|
-
Log4r::MDC.get('rack_env_PATH_INFO').should == '
|
77
|
+
Log4r::MDC.get('rack_env_PATH_INFO').should == '/error'
|
78
78
|
end
|
79
79
|
|
80
80
|
lambda {
|
@@ -55,10 +55,10 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
55
55
|
msg.should be_instance_of RuntimeError
|
56
56
|
msg.message.should == "I failed"
|
57
57
|
msg.backtrace.first.should =~ /resque_failure_handler_spec.rb/
|
58
|
-
Log4r::MDC.get('resque_worker').should ==
|
58
|
+
Log4r::MDC.get('resque_worker').should == nil
|
59
59
|
Log4r::MDC.get('resque_queue').should == "somequeue"
|
60
|
-
Log4r::MDC.get('resque_class').should ==
|
61
|
-
Log4r::MDC.get('resque_args').should ==
|
60
|
+
Log4r::MDC.get('resque_class').should == SomeJob
|
61
|
+
Log4r::MDC.get('resque_args').should == ["foo"]
|
62
62
|
end
|
63
63
|
|
64
64
|
run_resque_job(SomeJob, 'foo', :queue => :somequeue, :inline => true)
|
@@ -69,7 +69,7 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
69
69
|
Log4r::Logger['resquelogger'].should_receive(:error) do |msg|
|
70
70
|
msg.should be_instance_of RuntimeError
|
71
71
|
msg.message.should == "I failed"
|
72
|
-
Log4r::MDC.get('resque_class').should ==
|
72
|
+
Log4r::MDC.get('resque_class').should == SomeJobWithNilLogger
|
73
73
|
end
|
74
74
|
|
75
75
|
run_resque_job(SomeJobWithNilLogger, 'foo', :queue => :somequeue, :inline => true)
|
@@ -80,7 +80,7 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
80
80
|
Log4r::Logger['resquelogger'].should_receive(:error) do |msg|
|
81
81
|
msg.should be_instance_of RuntimeError
|
82
82
|
msg.message.should == "I failed"
|
83
|
-
Log4r::MDC.get('resque_class').should ==
|
83
|
+
Log4r::MDC.get('resque_class').should == SomeJobWithOtherLogger
|
84
84
|
end
|
85
85
|
|
86
86
|
run_resque_job(SomeJobWithOtherLogger, 'foo', :queue => :somequeue, :inline => true)
|
@@ -92,7 +92,7 @@ describe Log4rExceptionable::ResqueFailureHandler do
|
|
92
92
|
Log4r::Logger['SomeJobWithLogger'].should_receive(:error) do |msg|
|
93
93
|
msg.should be_instance_of RuntimeError
|
94
94
|
msg.message.should == "I failed"
|
95
|
-
Log4r::MDC.get('resque_class').should ==
|
95
|
+
Log4r::MDC.get('resque_class').should == SomeJobWithLogger
|
96
96
|
end
|
97
97
|
|
98
98
|
run_resque_job(SomeJobWithLogger, 'foo', :queue => :somequeue, :inline => true)
|