researchable_loggable 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -1
- data/lib/loggable/railtie.rb +7 -1
- data/lib/loggable/version.rb +1 -1
- data/node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a23495beab24247d68a2d16b22b47c63dc62907f5a0cd97a2bf239a697d7bae
|
4
|
+
data.tar.gz: 6da7d0c63b104be64d7ba13006db69cc2ff24610ea6494db4460db4db328620b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d169fe09836a0aaa5d9a8537590e77ccbfb2a8b8fd5998a71bd9eb1ec3913d20f84deec030274c361e20f18284ec10df825eb8d1635d17f561beb4678471eaa
|
7
|
+
data.tar.gz: 7675af41ca588f916a67dc4ac782bdd21480d0b043ef22f4412cc7dbae063d4be23eaad9bb95bf9d7d7e33abc2c265900e289c987c23787b920c7fd9238e5156
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [1.1.0](https://gitlab.com/researchable/general/gems/loggable/compare/v1.0.2...v1.1.0) (2023-07-06)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* **config:** Support other current_user_method ([e5797ba](https://gitlab.com/researchable/general/gems/loggable/commit/e5797ba6cc7f2a3e589895cf05ba2f4a109b10e1))
|
7
|
+
|
1
8
|
## [1.0.2](https://gitlab.com/researchable/general/gems/loggable/compare/v1.0.1...v1.0.2) (2023-06-27)
|
2
9
|
|
3
10
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -61,7 +61,11 @@ If loggable detects the presence of this gem, it will inject `transaction.id`, `
|
|
61
61
|
For a brand new Rails application, adding this gem to the Gemfile should be all the configuration that is needed. This
|
62
62
|
gem will automatically configure the Rails logger and lograge to follow the Researchable standard.
|
63
63
|
|
64
|
-
|
64
|
+
|
65
|
+
### Parameters
|
66
|
+
This are the parameters that can be configured in the `config.loggable` namespace:
|
67
|
+
|
68
|
+
`production_like`. By default loggable will only
|
65
69
|
modify how the logs look on production. This is because the format that this gem enforces is slightly less
|
66
70
|
human readable (in favour of machine readability and compatibility with the Elastic Common Schema) than the default
|
67
71
|
Rails one. For development, the more human readable format is preferred. However, if you want to override this and
|
@@ -71,6 +75,12 @@ are developing against this gem) then you may add the following to your `config/
|
|
71
75
|
config.loggable.production_like = true
|
72
76
|
```
|
73
77
|
|
78
|
+
`current_user_method`. This is the name of the method that will be called on the controller to get the current user. By default this is set to `current_user`. If you want to override this, you may add the following to your `config/application.rb` file:
|
79
|
+
```ruby
|
80
|
+
config.loggable.current_user_method = :my_current_user_method
|
81
|
+
```
|
82
|
+
This method is used for ECS logging, if the method is not found, the user.id field will be set to nil.
|
83
|
+
|
74
84
|
No other configuration options are provided because this gem seeks to enforce consistency across all applications.
|
75
85
|
|
76
86
|
For applications that already had some level of log customization, some cleanup might be needed:
|
data/lib/loggable/railtie.rb
CHANGED
@@ -9,9 +9,11 @@ module Loggable
|
|
9
9
|
# We add a new loggable namespace to the config object, to keep all the configuration related to this gem organized
|
10
10
|
config.loggable = ActiveSupport::OrderedOptions.new
|
11
11
|
config.loggable.production_like = false
|
12
|
+
config.loggable.current_user_method = :current_user
|
12
13
|
|
13
14
|
# Initializer runs before initialize_logger (found in Bootstrap) so from the very beginning we are logging using
|
14
15
|
# the ecs format, even during the initialization process
|
16
|
+
# rubocop:disable Metrics/BlockLength
|
15
17
|
initializer :loggable_web, before: :initialize_logger do
|
16
18
|
Rails.application.configure do
|
17
19
|
production_like = Rails.env.production? || config.loggable.production_like
|
@@ -25,10 +27,13 @@ module Loggable
|
|
25
27
|
config.lograge.base_controller_class = 'ApplicationController'
|
26
28
|
config.lograge.custom_payload do |controller|
|
27
29
|
response_code = controller.response.code
|
30
|
+
if controller.respond_to?(config.loggable.current_user_method)
|
31
|
+
user_id = controller.send(config.loggable.current_user_method).try(:id)
|
32
|
+
end
|
28
33
|
{
|
29
34
|
ecs: {
|
30
35
|
'source.ip': controller.request.ip,
|
31
|
-
'user.id':
|
36
|
+
'user.id': user_id,
|
32
37
|
'http.code': response_code
|
33
38
|
},
|
34
39
|
status: response_code
|
@@ -41,6 +46,7 @@ module Loggable
|
|
41
46
|
config.lograge.formatter = Loggable::Lograge::Formatter.new if production_like
|
42
47
|
end
|
43
48
|
end
|
49
|
+
# rubocop:enable Metrics/BlockLength
|
44
50
|
|
45
51
|
initializer :loggable_worker, before: :initializer_logger do
|
46
52
|
Rails.application.configure do
|
data/lib/loggable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: researchable_loggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Researchable
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06
|
11
|
+
date: 2023-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecs-logging
|
@@ -81,13 +81,13 @@ files:
|
|
81
81
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/prerelease/lib/test-gem/version.rb
|
82
82
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb
|
83
83
|
- sig/loggable.rbs
|
84
|
-
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0
|
84
|
+
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.1.0/README.md
|
85
85
|
licenses:
|
86
86
|
- MIT
|
87
87
|
metadata:
|
88
|
-
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0
|
88
|
+
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.1.0/README.md
|
89
89
|
source_code_uri: https://gitlab.com/researchable/general/gems/loggable
|
90
|
-
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0
|
90
|
+
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.1.0/CHANGELOG.md
|
91
91
|
post_install_message:
|
92
92
|
rdoc_options: []
|
93
93
|
require_paths:
|