rack-ltsv_logger 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b877c1c1d148d33b66c580fb4112e6ce9dad1e5
4
- data.tar.gz: 2bff1571091b41b391d4be16fc5d99f94fd9a06c
3
+ metadata.gz: a1e425b4056ae88b13545afbafc09630770bb961
4
+ data.tar.gz: d1bbfafa0e9ed39093083857ef3eeed2f8e70769
5
5
  SHA512:
6
- metadata.gz: d35ba9ab66040d12fed2f30130644787f03ef29cf926ffc3408269e898c4364cb88d5ae9371617a9b10ca76e8877ffde1650721a0aaf76591d3469cb1e52bd1c
7
- data.tar.gz: cd511826a96aa9bc77249fed37ed939aa134b7db18762b4a94362e5cf12a24af73cfef56858cfc9ba333054b9f7ec7010df6637bc7c2d33b06877b07948cc680
6
+ metadata.gz: 0a872d0e0b701ef967bfcc71bc970b9cfc6f552c78ead1e5059da4fe4fe2f98f8606ac103e420f0ed4414148f6dcb30450a9986a6dbe4d5f1bdf5b92107ded24
7
+ data.tar.gz: 3117c5f5154c37587b7a767628a4c12280d758a5893acfdc3c08b747db2298b7b55b3e8abd682ddf22074c9aac5aba1440c428d935afd29262136489c0511ce9
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 0.0.2 (2016/02/19)
2
+
3
+ Enhancements:
4
+
5
+ * Ensure to log even if `@app.call` raises an error (thanks to @sugilog)
6
+
7
+ ## 0.0.1 (2014/07/02)
8
+
9
+ First release
data/README.md CHANGED
@@ -8,14 +8,16 @@ cf. https://speakerdeck.com/mirakui/high-performance-rails-long-edition
8
8
 
9
9
  <img src="doc/x_runtime.png" alt="x_runtime" width="50%" height="50%"/>
10
10
 
11
- The Completed Time does not include routing time, and elapsed time on rack middleware layers, and so on.
12
- To measure the processing time accurately, it is necessary to insert a rack middleware to measure the time.
11
+ The Completed Time, which the default logger of rails shows,
12
+ does not include the routing time, and the elapsed time on rack middleware layers.
13
+ To measure the processing time accurately,
14
+ it is necessary to insert a rack middleware at the head of rack middleware stacks.
13
15
 
14
16
  ## Installation
15
17
 
16
18
  Add this line to your application's Gemfile:
17
19
 
18
- gem 'rack-ltsvlogger'
20
+ gem 'rack-ltsv_logger'
19
21
 
20
22
  And then execute:
21
23
 
@@ -25,22 +27,26 @@ And then execute:
25
27
 
26
28
  Insert Rack::LtsvLogger on the head of rack middlewares.
27
29
 
28
- Rails)
29
-
30
- Add following to config/environments/[env].rb
30
+ ### Rails
31
31
 
32
32
  ```ruby
33
- require 'rack/ltsvlogger'
34
- require 'logger'
33
+ # config/application.rb
34
+ class Application < Rails::Application
35
+ config.middleware.insert_after(0, Rack::LtsvLogger, $stdout)
36
+ end
37
+ ```
35
38
 
36
- config.middleware.insert_after(0, Rack::LtsvLogger, $stdout)
39
+ Middleware check.
40
+
41
+ ```
42
+ bundle exec rake middleware
37
43
  ```
38
44
 
39
- Sinatra)
45
+ ### Sinatra
40
46
 
41
47
  ```ruby
42
48
  # config.ru
43
- require 'rack/ltsvlogger'
49
+ require 'rack/ltsv_logger'
44
50
 
45
51
  use Rack::LtsvLogger, $stdout
46
52
  run App
@@ -48,11 +54,21 @@ run App
48
54
 
49
55
  ## Format
50
56
 
51
- Sample (line feeded):
57
+ Sample (line feeded, but actually tab seperated):
52
58
 
53
59
  ```
54
- time:2014-07-02T21:52:31+09:00 pid:15189 host:127.0.0.1 forwardedfor:127.0.0.2 user:user
55
- method:GET uri:/get query:?foo protocol:HTTP/1.1 status:200 size:- reqtime:0.000000
60
+ time:2014-07-02T21:52:31+09:00
61
+ pid:15189
62
+ host:127.0.0.1
63
+ forwardedfor:127.0.0.2
64
+ user:user
65
+ method:GET
66
+ uri:/get
67
+ query:?foo
68
+ protocol:HTTP/1.1
69
+ status:200
70
+ size:-
71
+ reqtime:0.000000
56
72
  ```
57
73
 
58
74
  ### Default Fields
@@ -14,7 +14,7 @@ module Rack
14
14
  began_at = Time.now.instance_eval { to_i + (usec/1000000.0) }
15
15
 
16
16
  status, headers, body = @app.call(env)
17
-
17
+ ensure
18
18
  now = Time.now
19
19
  reqtime = now.instance_eval { to_i + (usec/1000000.0) } - began_at
20
20
 
@@ -28,7 +28,7 @@ module Rack
28
28
  uri: env["PATH_INFO"],
29
29
  query: env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
30
30
  protocol: env["HTTP_VERSION"],
31
- status: status.to_s[0..3],
31
+ status: extract_status(status),
32
32
  size: extract_content_length(headers),
33
33
  reqtime: "%0.6f" % reqtime,
34
34
  }
@@ -47,8 +47,12 @@ module Rack
47
47
  end
48
48
 
49
49
  def extract_content_length(headers)
50
- value = headers['Content-Length'] or return '-'
50
+ value = headers && headers['Content-Length'] or return '-'
51
51
  value.to_s == '0' ? '-' : value
52
52
  end
53
+
54
+ def extract_status(status)
55
+ status.nil? ? "500" : status.to_s[0..3]
56
+ end
53
57
  end
54
58
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rack-ltsv_logger"
7
- spec.version = "0.0.1"
7
+ spec.version = "0.0.2"
8
8
  spec.authors = ["Naotoshi Seo"]
9
9
  spec.email = ["sonots@gmail.com"]
10
10
  spec.description = %q{A rack middleware to output access log in ltsv format}
@@ -8,6 +8,12 @@ describe Rack::LtsvLogger do
8
8
  }
9
9
  end
10
10
 
11
+ def error_app
12
+ lambda { |env|
13
+ raise ArgumentError, "error test"
14
+ }
15
+ end
16
+
11
17
  def parse_ltsv(ltsv)
12
18
  Hash[*(ltsv.chomp.split("\t").map {|e| e.split(":", 2) }.flatten)]
13
19
  end
@@ -70,4 +76,26 @@ describe Rack::LtsvLogger do
70
76
  expect(params['x_runtime']).to eq('1.234')
71
77
  end
72
78
  end
79
+
80
+ context 'when app error occured' do
81
+ let(:appends) do
82
+ { x_runtime: Proc.new {|env| '1.234' } }
83
+ end
84
+
85
+ subject do
86
+ @output = StringIO.new
87
+ Rack::Lint.new( Rack::LtsvLogger.new(error_app, @output, appends) )
88
+ end
89
+
90
+ it 'GET /get' do
91
+ expect {
92
+ Rack::MockRequest.new(subject).get('/get', env)
93
+ }.to raise_error ArgumentError
94
+
95
+ params = parse_ltsv(@output.string)
96
+ expect(params).not_to be_empty
97
+ expect(params['x_runtime']).to eq('1.234')
98
+ expect(params['status']).to eq('500')
99
+ end
100
+ end
73
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-ltsv_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".travis.yml"
120
+ - CHANGELOG.md
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.md
@@ -150,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  version: '0'
151
152
  requirements: []
152
153
  rubyforge_project:
153
- rubygems_version: 2.2.2
154
+ rubygems_version: 2.5.1
154
155
  signing_key:
155
156
  specification_version: 4
156
157
  summary: A rack middleware to output access log in ltsv format.