rack_xrk_log 0.1.5 → 0.1.6
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/lib/rack/xrk/adapter/base.rb +34 -0
- data/lib/rack/xrk/adapter/dispose.rb +46 -0
- data/lib/rack/xrk/log.rb +1 -1
- data/lib/spec/dispose_spec.rb +1 -0
- data/lib/spec/spec_helper.rb +10 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 553c859785a8fa45fa05f90efdef0e8a4369b1fb
|
4
|
+
data.tar.gz: e1b4db48fe49b73a8ef00e094cdfc16ab455d088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 865c341d72ab402508b81ef044bd4129f0bf1b4ed46efcaaedfda803be2c46548d4d68dcb519fb9af6bc133e1b5f5983caadf2de21ce09e89883d5469b395c73
|
7
|
+
data.tar.gz: 7c254f114f9bb1f48c71d4c60e468a8d04e4a95ee50825dc1ce93cf206bdd099de7a5bd8ebf4ae43ac8187837e1a78a10e8b17760de5a6516203eb92a53438a6
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rack
|
2
|
+
module XrkLog
|
3
|
+
class Base
|
4
|
+
attr_accessor :app, :logger, :app_name, :begin_at, :log_type
|
5
|
+
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
@log_type = "ACESS"
|
9
|
+
@logger = ::Logger.new("log/#{app.class.parent_name.downcase}_quality_access.log")
|
10
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
11
|
+
"#{begin_at}|#{app_name}|#{log_type}|#{msg}\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def formatter
|
16
|
+
raise NotImplementedError.new("You must implemente #{name} formatter method!")
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_runtime
|
20
|
+
(stop_at - begin_at).round(2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop_at
|
24
|
+
DateTime.now.strftime("%Q").to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
def write(env, body, status, header)
|
28
|
+
body = formatter(env, body, status, header)
|
29
|
+
@logger.info(body) unless body.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require ::File.expand_path("../../adapter/base", __FILE__)
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module XrkLog
|
5
|
+
class Dispose < Base
|
6
|
+
|
7
|
+
def initialize(app)
|
8
|
+
@app_name = app.class.parent_name
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def formatter(env, body, status, header)
|
13
|
+
@request = Rack::Request.new(env)
|
14
|
+
|
15
|
+
return if [%r{^/assets/}, %r{favicon.ico}].any?{|path| path.match(@request.path) }
|
16
|
+
|
17
|
+
query_string = @request.query_string.blank? ? "-" : @request.query_string
|
18
|
+
[
|
19
|
+
@request.ip,
|
20
|
+
@request.host_with_port,
|
21
|
+
total_runtime,
|
22
|
+
@request.scheme,
|
23
|
+
@request.content_length || 0,
|
24
|
+
@request.body.size || 0,
|
25
|
+
@request.request_method,
|
26
|
+
@request.path_info,
|
27
|
+
status,
|
28
|
+
query_string,
|
29
|
+
path_parameters(env),
|
30
|
+
json_with_nil(body[0]) || "-"
|
31
|
+
].join("|")
|
32
|
+
end
|
33
|
+
|
34
|
+
def json_with_nil(value)
|
35
|
+
JSON.parse(value) rescue nil
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def path_parameters(env)
|
40
|
+
opts = env["action_dispatch.request.path_parameters"]
|
41
|
+
return "#{opts[:controller]}/#{opts[:action]}" unless opts.blank?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/rack/xrk/log.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'spec_helper'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_xrk_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis Liu
|
@@ -63,8 +63,12 @@ files:
|
|
63
63
|
- Gemfile
|
64
64
|
- README.md
|
65
65
|
- Rakefile
|
66
|
+
- lib/rack/xrk/adapter/base.rb
|
67
|
+
- lib/rack/xrk/adapter/dispose.rb
|
66
68
|
- lib/rack/xrk/log.rb
|
67
69
|
- lib/rack/xrk/log/commonlogger.rb
|
70
|
+
- lib/spec/dispose_spec.rb
|
71
|
+
- lib/spec/spec_helper.rb
|
68
72
|
- rack_xrk_log.gemspec
|
69
73
|
homepage: https://github.com/louis813/rack_xrk_log
|
70
74
|
licenses:
|