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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63716c6fd344c619bcf67fc46017061364db4684
4
- data.tar.gz: cfd93192918c6fa220b6464bb4090e62f16e0087
3
+ metadata.gz: 553c859785a8fa45fa05f90efdef0e8a4369b1fb
4
+ data.tar.gz: e1b4db48fe49b73a8ef00e094cdfc16ab455d088
5
5
  SHA512:
6
- metadata.gz: 129b1b5d9cfe4e05b5b92e138e5b1deccfe66175a0b88f0f0e3610b36c492c36f1047e21b7190ec8976a02eb4eb97a5db66687b0b917cae4b94779cd51908173
7
- data.tar.gz: 36e8479e0bc6157b470539b4fd965e7ca4e682db14da4f3254cf6f84dfe205e824ee5445ae50168172a2582440e3a3d5b04d7e1812398026fe9c36b1ea4fa57b
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
@@ -3,7 +3,7 @@ require 'rack/xrk/log/commonlogger'
3
3
  module Rack
4
4
  module Xrk
5
5
  module Log
6
- VERSION = '0.1.5'
6
+ VERSION = '0.1.6'
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../lib/rack/xrk/adapter/dispose', __FILE__)
2
+ require 'rspec'
3
+ require 'rspec/core'
4
+ require 'rspec/mocks'
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec do |c|
8
+ c.syntax = [:should, :expect]
9
+ end
10
+ end
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.5
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: