rack-ougai 0.1.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: 27e100432cac9884d52ad4933f9d3224a2256e62
4
- data.tar.gz: cea9f134706c03c91166c25dffef970ccdce29a3
2
+ SHA256:
3
+ metadata.gz: 6e827d82e3bda428311a488e71e7a68407ebd6f9664fd4d93964696182ba884f
4
+ data.tar.gz: 60551ccad80cdf385be7f3f8a684f614f7b4ab5573bf28a56b5caa84e49e0cb2
5
5
  SHA512:
6
- metadata.gz: 9ee784842d6d78fb28f3d056cfbc1d38acd9b4ad4f5ce8113e977cbbfd9f640bee907850c0429eb2ffffa03dc5eebcd47203b22020e30c9036e187dd64e50ee6
7
- data.tar.gz: 73f60d0fa8de95aad6437376d9e6b7be15a4f93c71217ea525989b05baee2fc832f9d083029a0a813a7da09b10540b88c85737668c603e7d02e8f7e74d04019c
6
+ metadata.gz: 185c799a6a849b667d81d05818e5682c88fad6af4bb9a4d19cc3af6098573407a3588afe4d3159c17ab50f67ca91fcf62c7fd92054f6dcc8fe4dbdbaefabe0c9
7
+ data.tar.gz: 4443c2d0fc41196a02b037152642ba46ec137d852662d397f7207d38df42366710b31afacbdc3952267c1c392b46a5f8ade8f21f184cf88fe521e19e0f7bdfaf
data/.gitignore CHANGED
@@ -7,4 +7,6 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ .vscode
11
+
10
12
  Gemfile.lock
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.0.1
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in rack-ougai.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # Rack::Ougai #
1
+ # Rack::Ougai
2
+
2
3
  `Rack::Ougai` replaces the Rack logging system with an [Ougai](https://github.com/tilfin/ougai) logger
3
4
  that supports Bunyan-styled structured logging in JSON. It includes a few options for building those logs,
4
- as well as integration with (`Rack::RequestID`)[https://github.com/dancavallaro/rack-requestid].
5
+ as well as integration with [`Rack::RequestID`](https://github.com/dancavallaro/rack-requestid).
6
+
7
+ ## Installation
5
8
 
6
- ## Installation ##
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  ```ruby
@@ -12,18 +14,23 @@ gem 'rack-ougai'
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
17
+ ```sh
18
+ bundle
19
+ ```
16
20
 
17
21
  Or install it yourself as:
18
22
 
19
- $ gem install rack-ougai
23
+ ```sh
24
+ gem install rack-ougai
25
+ ```
26
+
27
+ ## Usage
20
28
 
21
- ## Usage ##
22
29
  Your `config.ru` should include directives similar to these. Obviously, `Rack::RequestID` is
23
30
  optional, but `Rack::Ougai::Logger` (or another logger provider) should be high in your middleware
24
31
  stack so as to push a logger down into the subsequent middleware.
25
32
 
26
- ```
33
+ ```ruby
27
34
  require 'rack/ougai'
28
35
  require 'rack/requestid'
29
36
 
@@ -35,27 +42,32 @@ use Rack::Ougai::AttachRequestID # Replaces logger with a child logger that's ta
35
42
  use Rack::Ougai::LogRequests # logs every request with timing data, request result, etc.
36
43
  ```
37
44
 
38
- ## Log Providers ##
45
+ ## Log Providers
46
+
47
+ ### `Rack::Ougai::Logger`
39
48
 
40
- ### `Rack::Ougai::Logger` ###
41
49
  Simple, no-configuration Ougai logger that accepts a `Logger` severity level.
42
50
 
43
- ### `Rack::Ougai::ConstantLogger` ###
51
+ ### `Rack::Ougai::ConstantLogger`
52
+
44
53
  Specify a preconfigured logger to be used for all requests. For example, in one project I
45
54
  build a global logger, separate from Rack, which is configured via a YAML file; I add it as the
46
55
  top level logger in Rack, too.
47
56
 
48
- ```
57
+ ```ruby
49
58
  require 'myproject/log'
50
59
 
51
60
  use Rack::Ougai::ConstantLogger, MyProject::Log # an instance of Ougai::Logging
52
61
  ```
53
62
 
54
- ## Contributing ##
55
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-ougai. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eropple/rack-ougai. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
+
67
+ ## License
56
68
 
57
- ## License ##
58
69
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
70
 
60
- ## Code of Conduct ##
61
- Everyone interacting in the Rack::Ougai project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rack-ougai/blob/master/CODE_OF_CONDUCT.md).
71
+ ## Code of Conduct
72
+
73
+ Everyone interacting in the Rack::Ougai project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/eropple/rack-ougai/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+
3
+ task default: :spec
@@ -7,13 +7,11 @@ module Rack
7
7
 
8
8
  def initialize(app, opts = {})
9
9
  @app = app
10
-
11
10
  @storage = opts[:storage] || proc { Thread.current }
12
11
  end
13
12
 
14
13
  def call(env)
15
14
  parent = env[Rack::RACK_LOGGER]
16
-
17
15
  request_id = env[REQUEST_ID_KEY]
18
16
 
19
17
  if request_id.nil?
@@ -3,29 +3,39 @@ require 'time'
3
3
  module Rack
4
4
  module Ougai
5
5
  class LogRequests
6
- def initialize(app, logger = nil)
6
+ def initialize(app, logger = nil, local: false)
7
7
  @app = app
8
8
  @logger = logger
9
+ @local = local
9
10
  end
10
11
 
11
12
  def call(env)
12
- status, headers, body = @app.call(env)
13
+ start_time = Time.now
14
+ status, headers, _body = @app.call(env)
13
15
  ensure
14
16
  logger = @logger || env[RACK_LOGGER]
15
- logger.info('HTTP Request', create_log(env, status, headers))
17
+ logger.info('http', create_log(start_time, env, status, headers))
16
18
  end
17
19
 
18
20
  private
19
21
 
20
- def create_log(env, status, header)
21
- {
22
- time: Time.now,
22
+ def create_log(start_time, env, status, _headers)
23
+ end_time = Time.now
24
+
25
+ ret = {
26
+ time: @local ? start_time : start_time.utc,
27
+ usec: end_time.usec - start_time.usec,
23
28
  remote_addr: env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"],
24
29
  method: env[REQUEST_METHOD],
25
30
  path: env[PATH_INFO],
26
31
  query: env[QUERY_STRING],
27
32
  status: status.to_i,
28
33
  }
34
+
35
+ request_id = env['HTTP_X_REQUEST_ID']
36
+ ret[:request_id] = request_id unless request_id.nil?
37
+
38
+ ret
29
39
  end
30
40
 
31
41
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Ougai
3
- VERSION = "0.1.0"
3
+ VERSION = "0.3.0".freeze
4
4
  end
5
5
  end
data/lib/rack/ougai.rb CHANGED
@@ -4,7 +4,7 @@ require "rack/ougai/logger"
4
4
  require "rack/ougai/constant_logger"
5
5
 
6
6
  require "rack/ougai/log_requests"
7
- require "rack/ougai/attach_requestid"
7
+ require "rack/ougai/attach_request_id"
8
8
 
9
9
  module Rack
10
10
  module Ougai
data/rack-ougai.gemspec CHANGED
@@ -1,12 +1,13 @@
1
1
  lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
3
4
  require "rack/ougai/version"
4
5
 
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = "rack-ougai"
7
8
  spec.version = Rack::Ougai::VERSION
8
- spec.authors = ["Toshimitsu Takahashi", "Ed Ropple"]
9
- spec.email = ["toshi@tilfin.com", "ed@edropple.com"]
9
+ spec.authors = ["Toshimitsu Takahashi", "Ed Ropple", "Pablo Crivella"]
10
+ spec.email = ["toshi@tilfin.com", "ed@edropple.com", "pablocrivella@gmail.com"]
10
11
 
11
12
  spec.summary = "Rack integration for the Ougai logger."
12
13
  spec.homepage = "https://github.com/eropple/rack-ougai"
@@ -19,9 +20,9 @@ Gem::Specification.new do |spec|
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ["lib"]
21
22
 
22
- spec.add_development_dependency "bundler", "~> 1.16"
23
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", "~> 12.0"
24
25
 
25
26
  spec.add_runtime_dependency "rack", "~> 2.0"
26
- spec.add_runtime_dependency "ougai", "~> 1.5"
27
+ spec.add_runtime_dependency "ougai", "~> 2.0"
27
28
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-ougai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshimitsu Takahashi
8
8
  - Ed Ropple
9
- autorequire:
9
+ - Pablo Crivella
10
+ autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2017-12-13 00:00:00.000000000 Z
13
+ date: 2022-05-11 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -17,28 +18,28 @@ dependencies:
17
18
  requirements:
18
19
  - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: '1.16'
21
+ version: '2.0'
21
22
  type: :development
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
26
  - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: '1.16'
28
+ version: '2.0'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: rake
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
33
  - - "~>"
33
34
  - !ruby/object:Gem::Version
34
- version: '10.0'
35
+ version: '12.0'
35
36
  type: :development
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
40
  - - "~>"
40
41
  - !ruby/object:Gem::Version
41
- version: '10.0'
42
+ version: '12.0'
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: rack
44
45
  requirement: !ruby/object:Gem::Requirement
@@ -59,24 +60,26 @@ dependencies:
59
60
  requirements:
60
61
  - - "~>"
61
62
  - !ruby/object:Gem::Version
62
- version: '1.5'
63
+ version: '2.0'
63
64
  type: :runtime
64
65
  prerelease: false
65
66
  version_requirements: !ruby/object:Gem::Requirement
66
67
  requirements:
67
68
  - - "~>"
68
69
  - !ruby/object:Gem::Version
69
- version: '1.5'
70
- description:
70
+ version: '2.0'
71
+ description:
71
72
  email:
72
73
  - toshi@tilfin.com
73
74
  - ed@edropple.com
75
+ - pablocrivella@gmail.com
74
76
  executables: []
75
77
  extensions: []
76
78
  extra_rdoc_files: []
77
79
  files:
78
80
  - ".gitignore"
79
81
  - ".rubocop.yml"
82
+ - ".tool-versions"
80
83
  - CODE_OF_CONDUCT.md
81
84
  - Gemfile
82
85
  - LICENSE.txt
@@ -85,7 +88,7 @@ files:
85
88
  - bin/console
86
89
  - bin/setup
87
90
  - lib/rack/ougai.rb
88
- - lib/rack/ougai/attach_requestid.rb
91
+ - lib/rack/ougai/attach_request_id.rb
89
92
  - lib/rack/ougai/constant_logger.rb
90
93
  - lib/rack/ougai/log_requests.rb
91
94
  - lib/rack/ougai/logger.rb
@@ -95,7 +98,7 @@ homepage: https://github.com/eropple/rack-ougai
95
98
  licenses:
96
99
  - MIT
97
100
  metadata: {}
98
- post_install_message:
101
+ post_install_message:
99
102
  rdoc_options: []
100
103
  require_paths:
101
104
  - lib
@@ -110,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
113
  - !ruby/object:Gem::Version
111
114
  version: '0'
112
115
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.6.13
115
- signing_key:
116
+ rubygems_version: 3.2.15
117
+ signing_key:
116
118
  specification_version: 4
117
119
  summary: Rack integration for the Ougai logger.
118
120
  test_files: []