rack_xrk_log 0.1.4
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 +7 -0
- data/.gitignore +4 -0
- data/Gemfile +9 -0
- data/README.md +18 -0
- data/Rakefile +4 -0
- data/lib/rack/xrk/log/commonlogger.rb +45 -0
- data/lib/rack/xrk/log.rb +9 -0
- data/rack_xrk_log.gemspec +25 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6c477b13da897a24979b7fa4ff8efee664dbab4
|
4
|
+
data.tar.gz: 6d5693a9313144351f54d599d3dd1a7750e61e4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c81a2b731648f5c931aa0e960bcd0ad53749ecd372b8c0ba49ebe133a68ba5830b819b3155e882078ea6b5796a9827b548f449af1f0f824210e76495a8a28e72
|
7
|
+
data.tar.gz: bc0940bd2e1eb07ac3bde446f46648350457ba409f1528eb5bc1de8cfe7351d92b776dd179dc8201c01f716579e2b499dea3ced5d8954b3125c7168322cbd07a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# rack_xrk_log
|
2
|
+
rack log for logstash
|
3
|
+
|
4
|
+
目前只适合公司的ruby项目使用
|
5
|
+
|
6
|
+
|
7
|
+
1. 增加 Gem
|
8
|
+
|
9
|
+
~~~
|
10
|
+
gem 'rack_xrk_log', :git => 'git@github.com:louis813/rack_xrk_log.git'
|
11
|
+
~~~
|
12
|
+
|
13
|
+
2. 在 config.ru 增加
|
14
|
+
|
15
|
+
~~~
|
16
|
+
require 'rack/xrk/log'
|
17
|
+
use Rack::Xrk::Log::CommonLogger, Rails.logger
|
18
|
+
~~~
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rack/commonlogger'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
module Xrk
|
6
|
+
module Log
|
7
|
+
class CommonLogger < Rack::CommonLogger
|
8
|
+
|
9
|
+
def initialize(app, logger=nil)
|
10
|
+
logger = ::Logger.new(::File.new("log/#{app.class.parent_name.downcase}_quality_access.log","a+"))
|
11
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
12
|
+
"#{msg}\n"
|
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
|
39
|
+
|
40
|
+
# TODO: Rack和Grape验证
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/rack/xrk/log.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/xrk/log'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack_xrk_log"
|
8
|
+
spec.version = Rack::Xrk::Log::VERSION
|
9
|
+
spec.authors = ["Louis Liu"]
|
10
|
+
spec.email = ["louisliu813@gmail.com"]
|
11
|
+
spec.description = "Gem for overwriting outputting JSON formatted access logs from Rack apps"
|
12
|
+
spec.summary = "Gem for overwriting outputting JSON formatted access logs from Rack apps"
|
13
|
+
spec.homepage = "https://github.com/louis813/rack_xrk_log"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
|
23
|
+
spec.add_dependency 'rack'
|
24
|
+
spec.add_dependency 'json'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_xrk_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Louis Liu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Gem for overwriting outputting JSON formatted access logs from Rack apps
|
56
|
+
email:
|
57
|
+
- louisliu813@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/rack/xrk/log.rb
|
67
|
+
- lib/rack/xrk/log/commonlogger.rb
|
68
|
+
- rack_xrk_log.gemspec
|
69
|
+
homepage: https://github.com/louis813/rack_xrk_log
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.6
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Gem for overwriting outputting JSON formatted access logs from Rack apps
|
93
|
+
test_files: []
|