researchable_loggable 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +143 -0
- data/LICENSE.txt +21 -0
- data/README.md +99 -0
- data/Rakefile +12 -0
- data/lib/loggable/ecs_logging/formatter_monkey_patch.rb +55 -0
- data/lib/loggable/lograge/formatter.rb +22 -0
- data/lib/loggable/railtie.rb +60 -0
- data/lib/loggable/version.rb +5 -0
- data/lib/loggable.rb +11 -0
- data/node_modules/semantic-release-rubygem/src/__tests__/fixtures/invalid-version-file/lib/test-gem/version.rb +5 -0
- data/node_modules/semantic-release-rubygem/src/__tests__/fixtures/prerelease/lib/test-gem/version.rb +5 -0
- data/node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb +5 -0
- data/sig/loggable.rbs +4 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9b483e9b1dcee65ba39a14ee62c76b0f81a92751ca755072bcae1c45c84954bb
|
4
|
+
data.tar.gz: c2de92b359b3d87bda96673eee61d141641a52e5e264f691f453f7800f01bd12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45d49f54d2b674d2f5e0e23fd659f7b2ae988732e5261a5070c529b4ed959aadc7c47b36a91078bc10d8edaef272a7a73d0abaa610c3b4c41dd01518e4715cc8
|
7
|
+
data.tar.gz: 7468411333b7e4d7014c29dc825e23a54902af8a895629b99ab09817cdedab2fddb668ca54108597bea3e494049356dce38df0d66e4dbdc41ee302d07e81dedc
|
data/.editorconfig
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
loggable
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## [1.0.1](https://gitlab.com/researchable/general/gems/loggable/compare/v1.0.0...v1.0.1) (2023-03-08)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **formatter:** undefined method merge for nil:NilClass ([1e110a0](https://gitlab.com/researchable/general/gems/loggable/commit/1e110a090d0c22ab8738a177d775c1f8146f6f2a))
|
7
|
+
|
8
|
+
# 1.0.0 (2023-03-08)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* loggable gem ([fbda454](https://gitlab.com/researchable/general/gems/loggable/commit/fbda4541ab6a67c9ef397845282614655d4ae092))
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in loggable.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
|
12
|
+
# TODO: remove ref once first implementation has been merged to master
|
13
|
+
gem 'ruboguide', git: 'https://gitlab.com/researchable/general/gems/ruboguide'
|
14
|
+
|
15
|
+
gem 'ecs-logging', '~> 1.0'
|
16
|
+
gem 'lograge'
|
17
|
+
gem 'logstash-event'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://gitlab.com/researchable/general/gems/ruboguide
|
3
|
+
revision: fd7b55c93c3ebfe63aed5cb7e5c9c38bd4a45020
|
4
|
+
specs:
|
5
|
+
ruboguide (0.1.0)
|
6
|
+
rubocop (= 1.23.0)
|
7
|
+
rubocop-performance (= 1.12.0)
|
8
|
+
rubocop-rails (= 2.12.4)
|
9
|
+
rubocop-rake (= 0.6.0)
|
10
|
+
rubocop-rspec (= 2.6.0)
|
11
|
+
|
12
|
+
PATH
|
13
|
+
remote: .
|
14
|
+
specs:
|
15
|
+
researchable_loggable (1.0.0)
|
16
|
+
ecs-logging (~> 1.0)
|
17
|
+
lograge
|
18
|
+
logstash-event
|
19
|
+
|
20
|
+
GEM
|
21
|
+
remote: https://rubygems.org/
|
22
|
+
specs:
|
23
|
+
actionpack (7.0.4.2)
|
24
|
+
actionview (= 7.0.4.2)
|
25
|
+
activesupport (= 7.0.4.2)
|
26
|
+
rack (~> 2.0, >= 2.2.0)
|
27
|
+
rack-test (>= 0.6.3)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
30
|
+
actionview (7.0.4.2)
|
31
|
+
activesupport (= 7.0.4.2)
|
32
|
+
builder (~> 3.1)
|
33
|
+
erubi (~> 1.4)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
36
|
+
activesupport (7.0.4.2)
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
38
|
+
i18n (>= 1.6, < 2)
|
39
|
+
minitest (>= 5.1)
|
40
|
+
tzinfo (~> 2.0)
|
41
|
+
ast (2.4.2)
|
42
|
+
builder (3.2.4)
|
43
|
+
concurrent-ruby (1.2.0)
|
44
|
+
crass (1.0.6)
|
45
|
+
diff-lcs (1.5.0)
|
46
|
+
ecs-logging (1.0.0)
|
47
|
+
erubi (1.12.0)
|
48
|
+
i18n (1.12.0)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
lograge (0.12.0)
|
51
|
+
actionpack (>= 4)
|
52
|
+
activesupport (>= 4)
|
53
|
+
railties (>= 4)
|
54
|
+
request_store (~> 1.0)
|
55
|
+
logstash-event (1.2.02)
|
56
|
+
loofah (2.19.1)
|
57
|
+
crass (~> 1.0.2)
|
58
|
+
nokogiri (>= 1.5.9)
|
59
|
+
method_source (1.0.0)
|
60
|
+
minitest (5.17.0)
|
61
|
+
nokogiri (1.14.1-x86_64-linux)
|
62
|
+
racc (~> 1.4)
|
63
|
+
parallel (1.22.1)
|
64
|
+
parser (3.2.1.0)
|
65
|
+
ast (~> 2.4.1)
|
66
|
+
racc (1.6.2)
|
67
|
+
rack (2.2.6.2)
|
68
|
+
rack-test (2.0.2)
|
69
|
+
rack (>= 1.3)
|
70
|
+
rails-dom-testing (2.0.3)
|
71
|
+
activesupport (>= 4.2.0)
|
72
|
+
nokogiri (>= 1.6)
|
73
|
+
rails-html-sanitizer (1.5.0)
|
74
|
+
loofah (~> 2.19, >= 2.19.1)
|
75
|
+
railties (7.0.4.2)
|
76
|
+
actionpack (= 7.0.4.2)
|
77
|
+
activesupport (= 7.0.4.2)
|
78
|
+
method_source
|
79
|
+
rake (>= 12.2)
|
80
|
+
thor (~> 1.0)
|
81
|
+
zeitwerk (~> 2.5)
|
82
|
+
rainbow (3.1.1)
|
83
|
+
rake (13.0.6)
|
84
|
+
regexp_parser (2.7.0)
|
85
|
+
request_store (1.5.1)
|
86
|
+
rack (>= 1.4)
|
87
|
+
rexml (3.2.5)
|
88
|
+
rspec (3.12.0)
|
89
|
+
rspec-core (~> 3.12.0)
|
90
|
+
rspec-expectations (~> 3.12.0)
|
91
|
+
rspec-mocks (~> 3.12.0)
|
92
|
+
rspec-core (3.12.1)
|
93
|
+
rspec-support (~> 3.12.0)
|
94
|
+
rspec-expectations (3.12.2)
|
95
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
96
|
+
rspec-support (~> 3.12.0)
|
97
|
+
rspec-mocks (3.12.3)
|
98
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
99
|
+
rspec-support (~> 3.12.0)
|
100
|
+
rspec-support (3.12.0)
|
101
|
+
rubocop (1.23.0)
|
102
|
+
parallel (~> 1.10)
|
103
|
+
parser (>= 3.0.0.0)
|
104
|
+
rainbow (>= 2.2.2, < 4.0)
|
105
|
+
regexp_parser (>= 1.8, < 3.0)
|
106
|
+
rexml
|
107
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
108
|
+
ruby-progressbar (~> 1.7)
|
109
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
110
|
+
rubocop-ast (1.26.0)
|
111
|
+
parser (>= 3.2.1.0)
|
112
|
+
rubocop-performance (1.12.0)
|
113
|
+
rubocop (>= 1.7.0, < 2.0)
|
114
|
+
rubocop-ast (>= 0.4.0)
|
115
|
+
rubocop-rails (2.12.4)
|
116
|
+
activesupport (>= 4.2.0)
|
117
|
+
rack (>= 1.1)
|
118
|
+
rubocop (>= 1.7.0, < 2.0)
|
119
|
+
rubocop-rake (0.6.0)
|
120
|
+
rubocop (~> 1.0)
|
121
|
+
rubocop-rspec (2.6.0)
|
122
|
+
rubocop (~> 1.19)
|
123
|
+
ruby-progressbar (1.11.0)
|
124
|
+
thor (1.2.1)
|
125
|
+
tzinfo (2.0.6)
|
126
|
+
concurrent-ruby (~> 1.0)
|
127
|
+
unicode-display_width (2.4.2)
|
128
|
+
zeitwerk (2.6.7)
|
129
|
+
|
130
|
+
PLATFORMS
|
131
|
+
x86_64-linux
|
132
|
+
|
133
|
+
DEPENDENCIES
|
134
|
+
ecs-logging (~> 1.0)
|
135
|
+
lograge
|
136
|
+
logstash-event
|
137
|
+
rake (~> 13.0)
|
138
|
+
researchable_loggable!
|
139
|
+
rspec (~> 3.0)
|
140
|
+
ruboguide!
|
141
|
+
|
142
|
+
BUNDLED WITH
|
143
|
+
2.4.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Mario Rios
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Loggable
|
2
|
+
|
3
|
+
Loggable is Researchable's gem to standardize how we do logging on Ruby on Rails applications.
|
4
|
+
|
5
|
+
## What it does
|
6
|
+
|
7
|
+
Loggable configures how your Rails applications outputs and formats logs, in a way that is easy to export and understand
|
8
|
+
by the elastic stack. Specifically it does the following:
|
9
|
+
|
10
|
+
1. Configures logs to be printed to stdout, so the elastic agent can read them.
|
11
|
+
2. Formats logs using the [ecs standard](https://www.elastic.co/guide/en/ecs/current/index.html).
|
12
|
+
3. Uses [lograge](https://github.com/roidrage/lograge) to improve how request logging is done.
|
13
|
+
4. Enables log-correlation for the elastic apm.
|
14
|
+
|
15
|
+
After adding this gem, your (production) logs will go from looking like this:
|
16
|
+
```
|
17
|
+
Started GET "/api/v1/profiles/my?hola=adiosa" for 172.19.0.1 at 2023-02-21 12:48:48 +0000
|
18
|
+
Processing by Api::V1::ProfilesController#my as */*
|
19
|
+
Parameters: {"hola"=>"adiosa"}
|
20
|
+
Completed 401 Unauthorized in 11ms (ActiveRecord: 0.0ms | MongoDB: 0.0ms | Allocations: 3355)
|
21
|
+
```
|
22
|
+
|
23
|
+
to looking like this:
|
24
|
+
```
|
25
|
+
{"@timestamp":"2023-02-21T13:11:56.457Z","log.level":"INFO","message":"method=GET path=/api/v1/profiles/my format=*/* controller=Api::V1::ProfilesController action=my status=200 duration=11.54 view=0.00 db=0.00 unpermitted_params=[\"hola\"] params={\"hola\"=>\"adiosa\"}","ecs.version":"1.4.0","source.ip":"172.19.0.1","user.id":null,"http.code":"200"}
|
26
|
+
```
|
27
|
+
|
28
|
+
While slightly less human readable, this is meant to be used along with a log aggregator that will display it in a
|
29
|
+
readable form. Development logs remain unaffected (see [Usage](#usage) for more on this).
|
30
|
+
|
31
|
+
## How it works
|
32
|
+
Loggable is a Railtie that overrides the default rails logger configuration. Right from the initialization process, the
|
33
|
+
logger is set to `::EcsLogging::Logger` and the default log level is set to `INFO` (this can be overridden in
|
34
|
+
application.rb or your environment configuration). It also configures lograge automatically. Note that the
|
35
|
+
base_controller_class is set to `'ApplicationController'`. All your controllers should extend from this class.
|
36
|
+
|
37
|
+
By default lograge and ::EcsLogging::Logger are not mutually compatible. The ECS formatter will try to render the output
|
38
|
+
of lograge as the message, however some of the fields in the lograge output are metadata. To fix this, this gem uses a
|
39
|
+
monkey patch on the ECS gem that flattens the lograge output onto the Ecs object.
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
Add this to your Gemfile (replace the tag with your intended one):
|
43
|
+
```ruby
|
44
|
+
gem 'loggable', git: 'https://gitlab.com/researchable/general/gems/loggable'
|
45
|
+
```
|
46
|
+
|
47
|
+
Additionally, if you want to be able to correlate logs with Elastic's APM traces, you may also add the elastic apm gem:
|
48
|
+
```ruby
|
49
|
+
gem 'elastic-apm'
|
50
|
+
```
|
51
|
+
|
52
|
+
Then execute:
|
53
|
+
```bash
|
54
|
+
$ bundle install
|
55
|
+
```
|
56
|
+
|
57
|
+
If loggable detects the presence of this gem, it will inject `transaction.id`, `span.id` and `trace.id` to the log line.
|
58
|
+
|
59
|
+
## Usage
|
60
|
+
|
61
|
+
For a brand new Rails application, adding this gem to the Gemfile should be all the configuration that is needed. This
|
62
|
+
gem will automatically configure the Rails logger and lograge to follow the Researchable standard.
|
63
|
+
|
64
|
+
There is only one parameter that is configurable, and that is `production_like`. By default loggable will only
|
65
|
+
modify how the logs look on production. This is because the format that this gem enforces is slightly less
|
66
|
+
human readable (in favour of machine readability and compatibility with the Elastic Common Schema) than the default
|
67
|
+
Rails one. For development, the more human readable format is preferred. However, if you want to override this and
|
68
|
+
log in the production format while on development (e.g. because you are troubleshooting a problem with the logs or you
|
69
|
+
are developing against this gem) then you may add the following to your `config/environment/development.rb` file:
|
70
|
+
```ruby
|
71
|
+
config.loggable.production_like = true
|
72
|
+
```
|
73
|
+
|
74
|
+
No other configuration options are provided because this gem seeks to enforce consistency across all applications.
|
75
|
+
|
76
|
+
For applications that already had some level of log customization, some cleanup might be needed:
|
77
|
+
|
78
|
+
1. If lograge was added to the Gemfile already, it may be removed. Loggable relies on lograge internally, and will
|
79
|
+
make it available to the Rails application.
|
80
|
+
2. Consequently, remove `config/lograge.rb` and all lograge related configuration.
|
81
|
+
3. Remove all existing log configuration, specially for production environments. Places to look for this
|
82
|
+
configuration are `config/application.rb` and `config/environment/production.rb`. If you chose to enable
|
83
|
+
`production_like` mode on your development environment, you might also want to cleanup
|
84
|
+
`config/environment/development.rb`. Things to look for when cleaning up are statements like `config.logger` and
|
85
|
+
`config.log_formatter` and anything with the word `log` or `logger` in it.
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
This gem is a Railtie, and it's meant to be run under a Rails project. The easiest way to develop and test this gem is
|
90
|
+
to add it to your Rails project locally by adding this to your Rails Gemfile:
|
91
|
+
```ruby
|
92
|
+
gem 'loggable', path: "<your local path to the loggable gem you're developing against>"
|
93
|
+
```
|
94
|
+
If your Rails application is being executed by a docker container, then map the local gem repository to a directory in
|
95
|
+
the container through a volume, and add the path of the volume to the Gemfile statement instead.
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ecs_logging/formatter'
|
4
|
+
|
5
|
+
module Loggable
|
6
|
+
module EcsLogging
|
7
|
+
# A monkey patch to the ::EcsLogging::Formatter to customize how messages from lograge are rendered
|
8
|
+
module FormatterMonkeyPatch
|
9
|
+
def call(severity, time, progname, msg, **extras)
|
10
|
+
base = {
|
11
|
+
'@timestamp': time.utc.iso8601(3),
|
12
|
+
'log.level': severity,
|
13
|
+
message: msg,
|
14
|
+
'ecs.version': '1.4.0'
|
15
|
+
}
|
16
|
+
|
17
|
+
base['log.logger'] = progname if progname
|
18
|
+
|
19
|
+
base.merge!(msg.except(:lograge)) if msg.is_a?(Hash) && msg.key?(:lograge)
|
20
|
+
base.merge!(extras) if extras
|
21
|
+
|
22
|
+
"#{JSON.fast_generate(base)}\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def apply_patch
|
27
|
+
const = find_const
|
28
|
+
mtd = find_method(const)
|
29
|
+
|
30
|
+
# byebug
|
31
|
+
const.prepend(self) if const && mtd && mtd.arity == -5
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def find_const
|
37
|
+
Kernel.const_get('::EcsLogging::Formatter')
|
38
|
+
rescue NameError
|
39
|
+
puts '[WARN] ::EcsLogging::Formatter not found. Patch could not be applied.' # rubocop:disable Rails/Output
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_method(const)
|
43
|
+
return unless const
|
44
|
+
|
45
|
+
method_name = :call
|
46
|
+
const.instance_method(method_name)
|
47
|
+
rescue NameError
|
48
|
+
puts "[WARN] '#{method_name}' method not found in '#{const}'. Patch could not be applied." # rubocop:disable Rails/Output
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Loggable::EcsLogging::FormatterMonkeyPatch.apply_patch
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lograge'
|
4
|
+
require 'active_support/core_ext/array'
|
5
|
+
|
6
|
+
module Loggable
|
7
|
+
module Lograge
|
8
|
+
# Custom formatter class that renders logs as ruby objects with just the ecs fields generated by the logger, the
|
9
|
+
# message, and a lograge flag so the ECS logger knows to process this further before rendering
|
10
|
+
class Formatter < ::Lograge::Formatters::KeyValue
|
11
|
+
def call(data)
|
12
|
+
(data[:ecs] || {}).merge(message: super(data), lograge: true)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def fields_to_display(data)
|
18
|
+
data.keys.excluding(%i[ecs])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ecs_logging/logger'
|
4
|
+
require 'rails'
|
5
|
+
|
6
|
+
module Loggable
|
7
|
+
# Railtie to configure logging before rails starts
|
8
|
+
class Railtie < Rails::Railtie
|
9
|
+
# We add a new loggable namespace to the config object, to keep all the configuration related to this gem organized
|
10
|
+
config.loggable = ActiveSupport::OrderedOptions.new
|
11
|
+
config.loggable.production_like = false
|
12
|
+
|
13
|
+
# Initializer runs before initialize_logger (found in Bootstrap) so from the very beginning we are logging using
|
14
|
+
# the ecs format, even during the initialization process
|
15
|
+
initializer :loggable_web, before: :initialize_logger do
|
16
|
+
Rails.application.configure do
|
17
|
+
production_like = Rails.env.production? || config.loggable.production_like
|
18
|
+
if production_like
|
19
|
+
Rails.logger = ::EcsLogging::Logger.new($stdout)
|
20
|
+
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase || 'INFO')
|
21
|
+
end
|
22
|
+
|
23
|
+
# lograge configuration
|
24
|
+
config.lograge.enabled = true
|
25
|
+
config.lograge.base_controller_class = 'ApplicationController'
|
26
|
+
config.lograge.custom_payload do |controller|
|
27
|
+
response_code = controller.response.code
|
28
|
+
{
|
29
|
+
ecs: {
|
30
|
+
'source.ip': controller.request.ip,
|
31
|
+
'user.id': controller.current_user.try(:id),
|
32
|
+
'http.code': response_code
|
33
|
+
},
|
34
|
+
status: response_code
|
35
|
+
}
|
36
|
+
end
|
37
|
+
config.lograge.custom_options = lambda do |event|
|
38
|
+
exceptions = %w[controller action format id]
|
39
|
+
{ params: event.payload[:params].except(*exceptions) }
|
40
|
+
end
|
41
|
+
config.lograge.formatter = Loggable::Lograge::Formatter.new if production_like
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
initializer :loggable_worker, before: :initializer_logger do
|
46
|
+
Rails.application.configure do
|
47
|
+
if defined?(Delayed::Worker)
|
48
|
+
if Rails.env.production? || config.loggable.production_like
|
49
|
+
Delayed::Worker.logger = ::EcsLogging::Logger.new($stdout)
|
50
|
+
Delayed::Worker.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase || 'INFO')
|
51
|
+
else
|
52
|
+
Delayed::Worker.logger = Logger.new($stdout)
|
53
|
+
Delayed::Worker.logger.level = Logger::DEBUG
|
54
|
+
Delayed::Worker.logger.datetime_format = '%Y-%m-%d %H:%M:%S'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/loggable.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'loggable/version'
|
4
|
+
require_relative 'loggable/railtie' if defined?(Rails::Railtie)
|
5
|
+
require_relative 'loggable/ecs_logging/formatter_monkey_patch'
|
6
|
+
require_relative 'loggable/lograge/formatter'
|
7
|
+
|
8
|
+
module Loggable
|
9
|
+
class Error < StandardError
|
10
|
+
end
|
11
|
+
end
|
data/sig/loggable.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: researchable_loggable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Researchable
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ecs-logging
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: lograge
|
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: logstash-event
|
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: |2
|
56
|
+
Researchable's Loggable relies on lograge and elastic's ecs format to log events in a way that is easy to ingest by
|
57
|
+
logstash. This enables log correlation with traces across multiple services.
|
58
|
+
email:
|
59
|
+
- info@researchable.nl
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".editorconfig"
|
65
|
+
- ".rspec"
|
66
|
+
- ".rubocop.yml"
|
67
|
+
- ".ruby-gemset"
|
68
|
+
- ".ruby-version"
|
69
|
+
- CHANGELOG.md
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/loggable.rb
|
76
|
+
- lib/loggable/ecs_logging/formatter_monkey_patch.rb
|
77
|
+
- lib/loggable/lograge/formatter.rb
|
78
|
+
- lib/loggable/railtie.rb
|
79
|
+
- lib/loggable/version.rb
|
80
|
+
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/invalid-version-file/lib/test-gem/version.rb
|
81
|
+
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/prerelease/lib/test-gem/version.rb
|
82
|
+
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb
|
83
|
+
- sig/loggable.rbs
|
84
|
+
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0.1/README.md
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata:
|
88
|
+
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0.1/README.md
|
89
|
+
source_code_uri: https://gitlab.com/researchable/general/gems/loggable
|
90
|
+
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0.1/CHANGELOG.md
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '3.0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.3.26
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Researchable's gem to standardize logging on all Rails applications.
|
110
|
+
test_files: []
|