rack_xrk_log 0.1.4 → 0.1.5
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/README.md +2 -2
- data/lib/rack/xrk/log/commonlogger.rb +13 -36
- data/lib/rack/xrk/log.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63716c6fd344c619bcf67fc46017061364db4684
|
4
|
+
data.tar.gz: cfd93192918c6fa220b6464bb4090e62f16e0087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 129b1b5d9cfe4e05b5b92e138e5b1deccfe66175a0b88f0f0e3610b36c492c36f1047e21b7190ec8976a02eb4eb97a5db66687b0b917cae4b94779cd51908173
|
7
|
+
data.tar.gz: 36e8479e0bc6157b470539b4fd965e7ca4e682db14da4f3254cf6f84dfe205e824ee5445ae50168172a2582440e3a3d5b04d7e1812398026fe9c36b1ea4fa57b
|
data/README.md
CHANGED
@@ -7,12 +7,12 @@ rack log for logstash
|
|
7
7
|
1. 增加 Gem
|
8
8
|
|
9
9
|
~~~
|
10
|
-
gem 'rack_xrk_log'
|
10
|
+
gem 'rack_xrk_log'
|
11
11
|
~~~
|
12
12
|
|
13
13
|
2. 在 config.ru 增加
|
14
14
|
|
15
15
|
~~~
|
16
16
|
require 'rack/xrk/log'
|
17
|
-
use Rack::
|
17
|
+
use Rack::XrkLog::CommonLogger
|
18
18
|
~~~
|
@@ -1,45 +1,22 @@
|
|
1
|
-
require 'rack/commonlogger'
|
2
1
|
require 'json'
|
2
|
+
require ::File.expand_path("../../adapter/dispose", __FILE__)
|
3
3
|
|
4
4
|
module Rack
|
5
|
-
module
|
6
|
-
|
7
|
-
class CommonLogger < Rack::CommonLogger
|
5
|
+
module XrkLog
|
6
|
+
class CommonLogger
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
super(app, logger)
|
15
|
-
end
|
16
|
-
|
17
|
-
def log(env, status, header, began_at)
|
18
|
-
logger = @logger || env['rack.errors']
|
19
|
-
|
20
|
-
return unless header["Content-Type"].present? && (header["Content-Type"].include? "text/html")
|
21
|
-
|
22
|
-
application_name = @app.class.parent_name
|
23
|
-
log_type = "ACESS"
|
24
|
-
client_ip_and_port = (env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_ADDR'] || '-')
|
25
|
-
response_data_length = env['action_controller.instance'].response_body.to_s.bytesize
|
26
|
-
query_string = (env['QUERY_STRING'].empty? ? "" : "?"+env['QUERY_STRING'])
|
27
|
-
controller = env['action_dispatch.request.path_parameters'][:controller]
|
28
|
-
action = env['action_dispatch.request.path_parameters'][:action]
|
29
|
-
return_content = env['action_controller.instance'].response_body
|
30
|
-
return_content = (return_content.empty? ? "" : return_content.to_s[0..99])
|
31
|
-
|
32
|
-
data = "#{began_at.to_i}, #{application_name}, #{log_type}, #{client_ip_and_port}, #{env['HTTP_HOST']}, #{(Time.now - began_at).to_i}, #{env['rack.url_scheme']}, #{env['CONTENT_LENGTH']}, #{response_data_length},".gsub("\n", "")
|
33
|
-
|
34
|
-
dynamic_params = "#{env['REQUEST_METHOD']} #{env['REQUEST_PATH']}, #{status.to_s[0..3]}, #{query_string}, #{controller} #{action}, , #{return_content}".gsub("\n", "")
|
35
|
-
|
36
|
-
data.concat(dynamic_params)
|
37
|
-
|
38
|
-
logger.info(data) if logger
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
@dispose = Dispose.new(@app)
|
11
|
+
end
|
39
12
|
|
40
|
-
|
41
|
-
|
13
|
+
def call(env)
|
14
|
+
@dispose.begin_at = DateTime.now.strftime("%Q").to_i
|
15
|
+
status, header, body = @app.call(env)
|
16
|
+
@dispose.write(env, body, status, header)
|
17
|
+
[status, header, body]
|
42
18
|
end
|
19
|
+
|
43
20
|
end
|
44
21
|
end
|
45
22
|
end
|
data/lib/rack/xrk/log.rb
CHANGED