justlogging-rails 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,7 +41,7 @@ module Justlogging
41
41
  end
42
42
 
43
43
  def formatted_exception
44
- return {} unless @exception
44
+ return {} unless exception?
45
45
  {
46
46
  :backtrace => @exception.backtrace,
47
47
  :exception => @exception.name,
@@ -67,15 +67,25 @@ module Justlogging
67
67
  :environment => Rails.env,
68
68
  :server => @env['SERVER_NAME'],
69
69
  :kind => 'http_request'
70
- }.tap { |o| o.merge!(formatted_payload) unless exception? }
70
+ }.merge(formatted_payload)
71
71
  end
72
72
 
73
73
  def formatted_payload
74
- @log_entry.payload.merge(
75
- :duration => @log_entry.duration,
76
- :time => @log_entry.time,
77
- :end => @log_entry.end
78
- ).tap { |o| o[:action] = "#{o.delete(:controller)}##{o[:action]}" }
74
+ if @log_entry
75
+ {
76
+ :duration => @log_entry.duration,
77
+ :time => @log_entry.time,
78
+ :end => @log_entry.end
79
+ }.merge(@log_entry.payload).tap do |o|
80
+ o[:action] = "#{o.delete(:controller)}##{o[:action]}"
81
+ end
82
+ else
83
+ if exception?
84
+ {:action => @exception.inspect.gsub(/^<#(.*)>$/, '\1')}
85
+ else
86
+ {}
87
+ end
88
+ end
79
89
  end
80
90
 
81
91
  def to_hash
@@ -37,7 +37,7 @@ module Justlogging
37
37
 
38
38
  def message(encoded_hash)
39
39
  Net::HTTP::Post.new(uri.request_uri).tap do |post|
40
- post.set_form_data(encoded_hash.reverse_merge('api_key' => api_key))
40
+ post.set_form_data({'api_key' => api_key}.merge(encoded_hash))
41
41
  end
42
42
  end
43
43
 
@@ -1,3 +1,3 @@
1
1
  module Justlogging
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -110,35 +110,20 @@ describe Justlogging::Transaction do
110
110
 
111
111
  describe '#formatted_log_entry' do
112
112
  subject { transaction.formatted_log_entry }
113
- before { transaction.stub(:request => mock(:fullpath => '/blog')) }
114
- before { Rails.stub(:env => 'care about it') }
115
-
116
- context "successfully handled request" do
117
- before { transaction.stub(:exception? => false) }
118
- before { transaction.stub(:formatted_payload => {:foo => :bar}) }
119
-
120
- it 'returns a formatted log_entry' do
121
- should == {
122
- :name => '/blog',
123
- :environment => 'care about it',
124
- :server => 'localhost',
125
- :kind => 'http_request',
126
- :foo => :bar
127
- }
128
- end
113
+ before do
114
+ transaction.stub(:request => mock(:fullpath => '/blog'))
115
+ Rails.stub(:env => 'care about it')
116
+ transaction.stub(:formatted_payload => {:foo => :bar})
129
117
  end
130
118
 
131
- context "exception" do
132
- before { transaction.stub(:exception? => true) }
133
-
134
- it 'returns a formatted log_entry' do
135
- should == {
136
- :name => '/blog',
137
- :environment => 'care about it',
138
- :server => 'localhost',
139
- :kind => 'http_request'
140
- }
141
- end
119
+ it 'returns a formatted log_entry' do
120
+ should == {
121
+ :name => '/blog',
122
+ :environment => 'care about it',
123
+ :server => 'localhost',
124
+ :kind => 'http_request',
125
+ :foo => :bar
126
+ }
142
127
  end
143
128
  end
144
129
 
@@ -146,21 +131,38 @@ describe Justlogging::Transaction do
146
131
  let(:start_time) { Time.parse('01-01-2001 10:00:00') }
147
132
  let(:end_time) { Time.parse('01-01-2001 10:00:01') }
148
133
  subject { transaction.formatted_payload }
149
- before do
150
- transaction.set_log_entry(mock(
151
- :name => 'name', :duration => 2, :time => start_time,
152
- :end => end_time,
153
- :payload => {:controller => 'controller', :action => 'action'}
154
- ))
134
+
135
+ context "with a present log entry" do
136
+ before do
137
+ transaction.set_log_entry(mock(
138
+ :name => 'name',
139
+ :duration => 2,
140
+ :time => start_time,
141
+ :end => end_time,
142
+ :payload => {:controller => 'controller', :action => 'action'}
143
+ ))
144
+ end
145
+
146
+ it 'returns the formatted payload of the log entry' do
147
+ should == {
148
+ :action => 'controller#action',
149
+ :duration => 2,
150
+ :time => start_time,
151
+ :end => end_time
152
+ }
153
+ end
155
154
  end
156
155
 
157
- it 'returns the formatted payload of the log entry' do
158
- should == {
159
- :action => 'controller#action',
160
- :duration => 2,
161
- :time => start_time,
162
- :end => end_time
163
- }
156
+ context "without a present log entry" do
157
+
158
+ it "returns the exception as the action if there is one" do
159
+ transaction.add_exception(mock(:inspect => '<#exceptional>'))
160
+ should == {:action => 'exceptional'}
161
+ end
162
+
163
+ it "returns an empty hash when no exception is set either" do
164
+ should == {}
165
+ end
164
166
  end
165
167
  end
166
168
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justlogging-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-07 00:00:00.000000000 Z
13
+ date: 2012-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails