request_id_logging 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +16 -0
- data/.rubocop.yml +53 -0
- data/.travis.yml +16 -3
- data/Gemfile +5 -1
- data/README.md +91 -7
- data/Rakefile +5 -3
- data/bin/console +4 -4
- data/lib/request_id_logging/formatter.rb +6 -1
- data/lib/request_id_logging/version.rb +1 -1
- data/request_id_logging.gemspec +4 -5
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0894cbd1ed7b5fe6213e45ea870cf96c4f3f2309'
|
4
|
+
data.tar.gz: 44ab371aa34316395193f8fda741d36d644b9b6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d201cd4b3dd828d1d5d4c9006219ad5aeabac70d714bd9096e0c1ef0747d0949c151cf56ba4a0fa8729f9996baf1cb0d8dde753f95c649aac786f6c06dec7bcd
|
7
|
+
data.tar.gz: 7e689492b480bdb00b2faf1561026457043e81ba0f8487760a12584b94d756fc04b395bdbfdb2be5aa51afd60942971f99de20c2026db8c8a44d3fbe8e724812
|
data/.codeclimate.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
##################### Linting #############################
|
2
|
+
|
3
|
+
##################### Metrics #############################
|
4
|
+
|
5
|
+
Metrics/BlockLength:
|
6
|
+
ExcludedMethods:
|
7
|
+
- describe
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 120
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 30
|
14
|
+
|
15
|
+
Metrics/ParameterLists:
|
16
|
+
CountKeywordArgs: false
|
17
|
+
|
18
|
+
##################### Performance #############################
|
19
|
+
|
20
|
+
Performance/FlatMap:
|
21
|
+
EnabledForFlattenWithoutParams: false
|
22
|
+
|
23
|
+
Performance/RedundantBlockCall:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
##################### Rails ##################################
|
27
|
+
|
28
|
+
Rails/SafeNavigation:
|
29
|
+
ConvertTry: true
|
30
|
+
|
31
|
+
Rails/SaveBang:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
##################### Security ##################################
|
35
|
+
|
36
|
+
##################### Style #################################
|
37
|
+
|
38
|
+
Style/AutoResourceCleanup:
|
39
|
+
Enabled: true
|
40
|
+
|
41
|
+
Style/Encoding:
|
42
|
+
Enabled: true
|
43
|
+
EnforcedStyle: never
|
44
|
+
|
45
|
+
Style/IfUnlessModifier:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/MultilineMethodCallIndentation:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
##################### Bundler #################################
|
52
|
+
Bundler/OrderedGems:
|
53
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
2
|
+
|
3
3
|
rvm:
|
4
|
+
- 2.0.0-p648
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.6
|
4
7
|
- 2.3.3
|
5
|
-
|
6
|
-
|
8
|
+
- 2.4.0
|
9
|
+
|
10
|
+
sudo: false
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- gem install bundler --no-document
|
14
|
+
script:
|
15
|
+
- 'bundle exec rspec'
|
16
|
+
after_success:
|
17
|
+
- 'bundle exec codeclimate-test-reporter'
|
18
|
+
|
19
|
+
cache: bundler
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# RequestIdLogging
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/request_id_logging.svg)](https://badge.fury.io/rb/request_id_logging)
|
3
4
|
[![Build Status](https://travis-ci.org/ryu39/request_id_logging.svg?branch=master)](https://travis-ci.org/ryu39/request_id_logging)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/ryu39/request_id_logging/badges/gpa.svg)](https://codeclimate.com/github/ryu39/request_id_logging)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/ryu39/request_id_logging/badges/coverage.svg)](https://codeclimate.com/github/ryu39/request_id_logging/coverage)
|
7
|
+
[![Issue Count](https://codeclimate.com/github/ryu39/request_id_logging/badges/issue_count.svg)](https://codeclimate.com/github/ryu39/request_id_logging)
|
4
8
|
|
5
|
-
|
9
|
+
RequestIdLogging provides a Rack middleware and a logger formatter to prepend X-Request-Id to log messages in your Rails app.
|
6
10
|
|
7
|
-
TODO: Delete this and the text above, and describe your gem
|
8
11
|
|
9
12
|
## Installation
|
10
13
|
|
@@ -22,22 +25,103 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
$ gem install request_id_logging
|
24
27
|
|
28
|
+
|
25
29
|
## Usage
|
26
30
|
|
27
|
-
|
31
|
+
First, add RequestIdLogging::Middleware to rack middlewares.
|
32
|
+
In your application.rb or environments/xxx.rb, insert RequestIdLogging::Middleware after ActionDispatch::RequestId.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
module MyApp
|
36
|
+
class Application < Rails::Application
|
37
|
+
# some configurations
|
38
|
+
# :
|
39
|
+
|
40
|
+
config.middleware.insert_after ActionDispatch::RequestId, RequestIdLogging::Middleware
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Next, set RequestIdLogging::Formatter instance to your logger's formatter.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
module MyApp
|
49
|
+
class Application < Rails::Application
|
50
|
+
# Set to Rails logger.
|
51
|
+
config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
|
52
|
+
config.logger.formatter = RequestIdLogging::Formatter.new
|
53
|
+
config.logger.formatter.datetime_format = '%Y-%m-%d %H:%M:%S.%L '.freeze
|
54
|
+
|
55
|
+
# And/Or set to your original logger's formatter.
|
56
|
+
config.x.my_app_logger = Logger.new('log/my_app.log')
|
57
|
+
config.x.my_app_logger.formatter = RequestIdLogging::Formatter.new
|
58
|
+
config.x.my_app_logger.formatter.datetime_format = '%Y-%m-%d %H:%M:%S.%L '.freeze
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Then, loggers write logs with request id.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Rails.logger.info 'test'
|
67
|
+
# => I, [2016-12-03 20:52:59.879 #106] INFO -- : [aca576f4-f4fa-4c2a-b172-d8fb5cc37681] test
|
68
|
+
|
69
|
+
Rails.configuration.x.my_app_logger.info 'test my_app'
|
70
|
+
# => I, [2016-12-03 20:53:00.184 #106] INFO -- : [aca576f4-f4fa-4c2a-b172-d8fb5cc37681] test my_app
|
71
|
+
```
|
72
|
+
|
73
|
+
### Request id customization
|
74
|
+
|
75
|
+
You can customize request id using `:request_id_proc` option.
|
76
|
+
|
77
|
+
Following example extracts first 8 characters from request id and uses it as request id.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
logger = Logger.new('log/my_app.log')
|
81
|
+
logger.formatter = RequestIdLogging::Formatter.new(request_id_proc: ->(id) { id&.first(8) }) # &. operator requires >= Ruby 2.3.0
|
82
|
+
|
83
|
+
logger.info 'customize request id'
|
84
|
+
# => I, [2016-12-03 20:46:31.399 #83] INFO -- : [4a966ef6] customize request id
|
85
|
+
```
|
86
|
+
|
87
|
+
### Formatter delegation
|
88
|
+
|
89
|
+
You can use your original formatter using `:formatter` option.
|
90
|
+
|
91
|
+
If this option is specified, RequestIdLogging::Formatter prepends request id to `msg` and calls your formatter#call.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
original_formatter = Logger::Formatter.new
|
95
|
+
def original_formatter.call(severity, time, progname, msg)
|
96
|
+
"MyFormatter: #{severity}, #{time}, #{progname}, #{msg}\n"
|
97
|
+
end
|
98
|
+
|
99
|
+
logger = Logger.new('log/my_app.log')
|
100
|
+
logger.formatter = RequestIdLogging::Formatter.new(formatter: original_formatter)
|
101
|
+
|
102
|
+
logger.info 'formatter delegation'
|
103
|
+
# => MyFormatter: INFO, 2016-12-04 10:47, , [6a8ef6bb-cf75-4ddf-a111-72c285c3ebda] test my_app
|
104
|
+
```
|
105
|
+
|
28
106
|
|
29
107
|
## Development
|
30
108
|
|
31
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
109
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
110
|
+
Then, run `rake spec` to run the tests.
|
111
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
112
|
+
|
113
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
114
|
+
To release a new version, update the version number in `version.rb`,
|
115
|
+
and then run `bundle exec rake release`, which will create a git tag for the version,
|
116
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
117
|
|
33
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
118
|
|
35
119
|
## Contributing
|
36
120
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/request_id_logging.
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/request_id_logging.
|
122
|
+
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.
|
38
123
|
|
39
124
|
|
40
125
|
## License
|
41
126
|
|
42
127
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
-
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new(:spec)
|
5
7
|
|
6
|
-
task :
|
8
|
+
task default: :spec
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'request_id_logging'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
10
|
+
# require 'pry'
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
@@ -2,6 +2,7 @@ require 'request_id_logging/constants'
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
module RequestIdLogging
|
5
|
+
# A logger formatter which prepends request_id to message.
|
5
6
|
class Formatter < Logger::Formatter
|
6
7
|
DEFAULT_REQ_ID_PROC = ->(id) { id }
|
7
8
|
|
@@ -19,7 +20,11 @@ module RequestIdLogging
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def call(severity, time, progname, msg)
|
22
|
-
|
23
|
+
if @original_formatter
|
24
|
+
@original_formatter.call(severity, time, progname, new_msg(msg))
|
25
|
+
else
|
26
|
+
super(severity, time, progname, new_msg(msg))
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
data/request_id_logging.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'request_id_logging/version'
|
@@ -9,10 +8,9 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ['ryu39']
|
10
9
|
spec.email = ['dev.ryu39@gmail.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
|
15
|
-
EOS
|
11
|
+
spec.summary = 'Logging with request id in your Rails app.'
|
12
|
+
spec.description = 'This gems provide a Rack middleware and a logger formatter ' \
|
13
|
+
'for logging with request id in your Rails app.'
|
16
14
|
spec.homepage = 'https://github.com/ryu39/request_id_logging'
|
17
15
|
spec.license = 'MIT'
|
18
16
|
|
@@ -26,4 +24,5 @@ EOS
|
|
26
24
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'rubocop'
|
29
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_id_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryu39
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,16 +52,32 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
|
56
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gems provide a Rack middleware and a logger formatter for logging
|
70
|
+
with request id in your Rails app.
|
57
71
|
email:
|
58
72
|
- dev.ryu39@gmail.com
|
59
73
|
executables: []
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
77
|
+
- ".codeclimate.yml"
|
63
78
|
- ".gitignore"
|
64
79
|
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
65
81
|
- ".travis.yml"
|
66
82
|
- CODE_OF_CONDUCT.md
|
67
83
|
- Gemfile
|
@@ -96,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
112
|
version: '0'
|
97
113
|
requirements: []
|
98
114
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.6.
|
115
|
+
rubygems_version: 2.6.8
|
100
116
|
signing_key:
|
101
117
|
specification_version: 4
|
102
118
|
summary: Logging with request id in your Rails app.
|