pier_logging 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +40 -0
- data/README.md +64 -8
- data/lib/pier_logging.rb +4 -3
- data/lib/pier_logging/request_logger.rb +3 -3
- data/lib/pier_logging/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff84f20b75432ad8b9677f443507f89618bb16cb10fb540cea1f15e9ef38f44
|
4
|
+
data.tar.gz: 3ccee8b70edaf743e2a4696eb1b405c505b0d6d6d2aaffd565d761e318feca21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16da7e85dbb12163a9bc5c9d660258ef51b0d968e55be28c04159cad2481ed62f3349e902a3dd9cc74417ec15c4d8bb0d3decab17cd717eecdb39a404d821b48
|
7
|
+
data.tar.gz: 88f4e611ab39c17fdb669bae02cffd16a6466e8c11d1403a9a60c84aceb834f707d212e72f908ca532fd1802c1522e1c497229082cf0a7b55235662287258e3a
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# This is a comment.
|
2
|
+
# Each line is a file pattern followed by one or more owners.
|
3
|
+
|
4
|
+
# These owners will be the default owners for everything in
|
5
|
+
# the repo. Unless a later match takes precedence,
|
6
|
+
# @global-owner1 and @global-owner2 will be requested for
|
7
|
+
# review when someone opens a pull request.
|
8
|
+
* @pier-digital/backend
|
9
|
+
.github/* @pier-digital/backend @pier-digital/devops
|
10
|
+
bin/* @pier-digital/backend @pier-digital/devops
|
11
|
+
|
12
|
+
# # Order is important; the last matching pattern takes the most
|
13
|
+
# # precedence. When someone opens a pull request that only
|
14
|
+
# # modifies JS files, only @js-owner and not the global
|
15
|
+
# # owner(s) will be requested for a review.
|
16
|
+
# *.js @js-owner
|
17
|
+
|
18
|
+
# # You can also use email addresses if you prefer. They'll be
|
19
|
+
# # used to look up users just like we do for commit author
|
20
|
+
# # emails.
|
21
|
+
# *.go docs@example.com
|
22
|
+
|
23
|
+
# # In this example, @doctocat owns any files in the build/logs
|
24
|
+
# # directory at the root of the repository and any of its
|
25
|
+
# # subdirectories.
|
26
|
+
# /build/logs/ @doctocat
|
27
|
+
|
28
|
+
# # The `docs/*` pattern will match files like
|
29
|
+
# # `docs/getting-started.md` but not further nested files like
|
30
|
+
# # `docs/build-app/troubleshooting.md`.
|
31
|
+
# docs/* docs@example.com
|
32
|
+
|
33
|
+
# # In this example, @octocat owns any file in an apps directory
|
34
|
+
# # anywhere in your repository.
|
35
|
+
# apps/ @octocat
|
36
|
+
|
37
|
+
# # In this example, @doctocat owns any file in the `/docs`
|
38
|
+
# # directory in the root of your repository.
|
39
|
+
# /docs/ @doctocat
|
40
|
+
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# PierLogging
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A gem developed by [PIER](https://www.pier.digital/) to standardize our logs (request and general-purpose)
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,17 +20,75 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
- Create an initializer at `config/initializers/pier_logging.rb` to configure the gem.
|
24
|
+
- Configure General-purpose logging, Request logging and register the request logger rails middleware.
|
25
|
+
- Configure your logger on `config/application.rb` to use `PierLogging::Logger`
|
26
|
+
|
27
|
+
### General-purpose logging
|
28
|
+
|
29
|
+
Use `PierLogging.configure_logger` block to configure general-purpose logs. Accepted configs are:
|
30
|
+
|
31
|
+
| config | Required | Type | Default |
|
32
|
+
| --------- | --------:| -------------------------:| ----------------------------------:|
|
33
|
+
| app_name | true | string | nil |
|
34
|
+
| env | true | string | nil |
|
35
|
+
| formatter | false | `Ougai::Formatters::Base` | `PierLogging::Formatter::Json.new` |
|
36
|
+
|
37
|
+
### Request logging
|
38
|
+
|
39
|
+
Use `PierLogging.configure_request_logger` block to configure request logs. Accepted configs are:
|
40
|
+
|
41
|
+
| config | Required | Type | Default |
|
42
|
+
| ---------------- | --------:| ---------------:| ----------:|
|
43
|
+
| enabled | false | boolean | false |
|
44
|
+
| user_info_getter | true | block (headers) | nil |
|
45
|
+
|
46
|
+
The block passed to `user_info_getter` receives the headers of the request so you can use your headers to define the username or role.
|
26
47
|
|
27
|
-
|
48
|
+
You have at your disposal the following helper methods:
|
28
49
|
|
29
|
-
|
50
|
+
- has_basic_credentials(headers): checks if there are basic auth credentials in the header
|
51
|
+
- get_basic_credentials_user(headers): get the user from the basic auth credential
|
30
52
|
|
31
|
-
|
53
|
+
### Example
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# config/initializers/pier_logging.rb
|
57
|
+
|
58
|
+
PierLogging.configure_logger do |config|
|
59
|
+
config.app_name = Rails.application.class.module_parent_name.underscore.dasherize
|
60
|
+
config.env = Rails.env
|
61
|
+
config.formatter = Rails.env.production? ? PierLogging::Formatter::Json.new :
|
62
|
+
PierLogging::Formatter::Readable.new
|
63
|
+
end
|
64
|
+
|
65
|
+
PierLogging.configure_request_logger do |config|
|
66
|
+
config.user_info_getter do |headers|
|
67
|
+
if headers['MY-USER-HEADER'].present?
|
68
|
+
{ username: headers['MY-USER-HEADER'] }
|
69
|
+
elsif has_basic_credentials?(headers)
|
70
|
+
{ username: get_basic_credentials_user(headers) }
|
71
|
+
else
|
72
|
+
{ username: 'anonymous' }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
config.enabled = ENV.fetch('REQUEST_LOG_ENABLED', 'true') == 'true'
|
76
|
+
end
|
77
|
+
|
78
|
+
Rails.application.config.middleware.use PierLogging::RequestLogger, PierLogging::Logger.new(STDOUT)
|
79
|
+
```
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# config/application.rb
|
83
|
+
|
84
|
+
# ...
|
85
|
+
config.logger = PierLogging::Logger.new(STDOUT)
|
86
|
+
# ...
|
87
|
+
```
|
32
88
|
|
33
89
|
## Contributing
|
34
90
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pier-digital/pier_logging.
|
36
92
|
|
37
93
|
## License
|
38
94
|
|
data/lib/pier_logging.rb
CHANGED
@@ -57,12 +57,13 @@ module PierLogging
|
|
57
57
|
@enabled = false
|
58
58
|
end
|
59
59
|
|
60
|
-
def user_info_getter(
|
61
|
-
raise ArgumentError, "Config 'user_info_getter' must be a 'Proc'" unless
|
62
|
-
@user_info_getter =
|
60
|
+
def user_info_getter=(proc)
|
61
|
+
raise ArgumentError, "Config 'user_info_getter' must be a 'Proc'" unless proc.is_a? Proc
|
62
|
+
@user_info_getter = proc
|
63
63
|
end
|
64
64
|
|
65
65
|
def enabled=(enabled = false)
|
66
|
+
raise ArgumentError, "Config 'enabled' must be a 'boolean'" unless !!enabled == enabled
|
66
67
|
@enabled = enabled
|
67
68
|
end
|
68
69
|
end
|
@@ -88,11 +88,11 @@ module PierLogging
|
|
88
88
|
|
89
89
|
def parse_body(body)
|
90
90
|
if body.is_a? String # when string
|
91
|
-
|
91
|
+
Oj.load(body, allow_blank: true)
|
92
92
|
elsif body.is_a? Array # Grape body
|
93
|
-
|
93
|
+
Oj.load(body.last, allow_blank: true)
|
94
94
|
elsif body.is_a? ActionDispatch::Response::RackBody # Rails body
|
95
|
-
|
95
|
+
Oj.load(body.body, allow_blank: true)
|
96
96
|
else
|
97
97
|
body
|
98
98
|
end
|
data/lib/pier_logging/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pier_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Banduk
|
@@ -115,6 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- ".github/CODEOWNERS"
|
118
119
|
- ".github/workflows/publish.yml"
|
119
120
|
- ".gitignore"
|
120
121
|
- ".ruby-version"
|