lograge 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/lograge.rb CHANGED
@@ -25,20 +25,23 @@ module Lograge
25
25
  end
26
26
 
27
27
  def self.remove_existing_log_subscriptions
28
- %w(redirect_to process_action start_processing send_data send_file write_fragment read_fragment exist_fragment? expire_fragment expire_page write_page).each do |event|
29
- unsubscribe_from_event(:action_controller, event)
30
- end
31
-
32
- %w{render_template render_partial render_collection}.each do |event|
33
- unsubscribe_from_event(:action_view, event)
28
+ ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
29
+ case subscriber
30
+ when ActionView::LogSubscriber
31
+ unsubscribe(:action_view, subscriber)
32
+ when ActionController::LogSubscriber
33
+ unsubscribe(:action_controller, subscriber)
34
+ end
34
35
  end
35
36
  end
36
37
 
37
- def self.unsubscribe_from_event(component, event)
38
- delegate_type = component.to_s.classify
39
- ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
40
- if listener.inspect =~ /delegate[^a-z]+#{delegate_type}/
41
- ActiveSupport::Notifications.unsubscribe listener
38
+ def self.unsubscribe(component, subscriber)
39
+ events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
40
+ events.each do |event|
41
+ ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
42
+ if listener.instance_variable_get('@delegate') == subscriber
43
+ ActiveSupport::Notifications.unsubscribe listener
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -25,6 +25,8 @@ module Lograge
25
25
  elsif payload[:exception]
26
26
  exception, message = payload[:exception]
27
27
  " status=500 error='#{exception}:#{message}'"
28
+ else
29
+ " status=0"
28
30
  end
29
31
  end
30
32
 
@@ -1,3 +1,3 @@
1
1
  module Lograge
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -79,6 +79,13 @@ describe Lograge::RequestLogSubscriber do
79
79
  log_output.string.should =~ /error='AbstractController::ActionNotFound:Route not found'/
80
80
  end
81
81
 
82
+ it "should return an unknown status when no status or exception is found" do
83
+ event.payload[:status] = nil
84
+ event.payload[:exception] = nil
85
+ subscriber.process_action(event)
86
+ log_output.string.should =~ /status=0/
87
+ end
88
+
82
89
  describe "with a redirect" do
83
90
  before do
84
91
  Thread.current[:lograge_location] = "http://www.example.com"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lograge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70345743126700 !ruby/object:Gem::Requirement
16
+ requirement: &70342810146560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70345743126700
24
+ version_requirements: *70342810146560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard-rspec
27
- requirement: &70345743136340 !ruby/object:Gem::Requirement
27
+ requirement: &70342810146040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70345743136340
35
+ version_requirements: *70342810146040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &70345743177800 !ruby/object:Gem::Requirement
38
+ requirement: &70342810145560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70345743177800
46
+ version_requirements: *70342810145560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: actionpack
49
- requirement: &70345743191500 !ruby/object:Gem::Requirement
49
+ requirement: &70342810144900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70345743191500
57
+ version_requirements: *70342810144900
58
58
  description: Tame Rails' multi-line logging into a single line per request
59
59
  email:
60
60
  - meyer@paperplanes.de