rack-ltsv_logger 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +30 -14
- data/lib/rack/ltsv_logger.rb +7 -3
- data/rack-ltsv_logger.gemspec +1 -1
- data/spec/ltsv_logger_spec.rb +28 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1e425b4056ae88b13545afbafc09630770bb961
|
4
|
+
data.tar.gz: d1bbfafa0e9ed39093083857ef3eeed2f8e70769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a872d0e0b701ef967bfcc71bc970b9cfc6f552c78ead1e5059da4fe4fe2f98f8606ac103e420f0ed4414148f6dcb30450a9986a6dbe4d5f1bdf5b92107ded24
|
7
|
+
data.tar.gz: 3117c5f5154c37587b7a767628a4c12280d758a5893acfdc3c08b747db2298b7b55b3e8abd682ddf22074c9aac5aba1440c428d935afd29262136489c0511ce9
|
data/CHANGELOG.md
ADDED
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
|
12
|
-
|
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-
|
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
|
-
|
34
|
-
|
33
|
+
# config/application.rb
|
34
|
+
class Application < Rails::Application
|
35
|
+
config.middleware.insert_after(0, Rack::LtsvLogger, $stdout)
|
36
|
+
end
|
37
|
+
```
|
35
38
|
|
36
|
-
|
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/
|
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
|
55
|
-
|
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
|
data/lib/rack/ltsv_logger.rb
CHANGED
@@ -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
|
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
|
data/rack-ltsv_logger.gemspec
CHANGED
@@ -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.
|
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}
|
data/spec/ltsv_logger_spec.rb
CHANGED
@@ -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.
|
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:
|
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.
|
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.
|