logjoy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +27 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/LOGRAGE_README.md +50 -0
- data/README.md +90 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/logjoy/log_subscribers/action_controller.rb +50 -0
- data/lib/logjoy/railtie.rb +27 -0
- data/lib/logjoy/version.rb +5 -0
- data/lib/logjoy.rb +57 -0
- data/logjoy.gemspec +33 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90661f240bf5c1fb3c326ecf2f95e7c5d1ed9049c71f58c8f982b4e16eba5903
|
4
|
+
data.tar.gz: 07e1678a7a947eba4aa63edee0914759026a0e34525095c8e4f285d794ed167e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e9ad2e6fd27e47be5f9f7808de85ba775a0c2e92400b1cb2ef7683ba68b88793440bcead1c5235375c9751cf6657bf3232f7ac5b5b48084e4721b500f40378b
|
7
|
+
data.tar.gz: 298bd247f702952959f06bbdb85bca43e7c6c174da7352914c79048661d661c39c981172bb9ab477be096d3fccc6dbd6ffb883e705d872b84acfd1e42c862065
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.7.2
|
5
|
+
|
6
|
+
Layout/LineLength:
|
7
|
+
Max: 120
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
EnforcedStyle: single_quotes
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Naming/AccessorMethodName:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Naming/VariableNumber:
|
25
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2021-09-27 12:48:33 UTC using RuboCop version 1.21.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: Keywords, RequireColon.
|
12
|
+
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE
|
13
|
+
Style/CommentAnnotation:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/logjoy.rb'
|
16
|
+
|
17
|
+
# Offense count: 5
|
18
|
+
# Configuration parameters: AllowedConstants.
|
19
|
+
Style/Documentation:
|
20
|
+
Exclude:
|
21
|
+
- 'spec/**/*'
|
22
|
+
- 'test/**/*'
|
23
|
+
- 'lib/logjoy.rb'
|
24
|
+
- 'lib/logjoy/configuration.rb'
|
25
|
+
- 'lib/logjoy/formatter.rb'
|
26
|
+
- 'lib/logjoy/log_subscribers/action_controller.rb'
|
27
|
+
- 'lib/logjoy/railtie.rb'
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at patmcgee331@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in logjoy.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'minitest', '5.14.4'
|
9
|
+
gem 'pry', '0.14.1'
|
10
|
+
gem 'rails', '6.1.4.1'
|
11
|
+
gem 'rake', '13.0.6'
|
12
|
+
gem 'rubocop', '1.21.0'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Pat McGee
|
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/LOGRAGE_README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Lograge vs. Logjoy
|
2
|
+
|
3
|
+
Please note: this comparison is accurate as of the writing of this document -
|
4
|
+
[lograge v0.11.2](https://github.com/roidrage/lograge/releases/tag/v0.11.2)
|
5
|
+
|
6
|
+
So if you are reading this at a later date this may not be entirely accurate.
|
7
|
+
|
8
|
+
Both this gem and lograge are relatively small codebases so I encourage you to
|
9
|
+
take a look and make your own comparison.
|
10
|
+
|
11
|
+
## How Lograge works:
|
12
|
+
|
13
|
+
- Monkeypatches `Rails::Rack::Logger`
|
14
|
+
- Monkeypatches `ActionCable` classes and adds custom
|
15
|
+
`ActiveSupport::Notifications`
|
16
|
+
- Monkeypatches `ActionCable::Server` and replaces the logger w/ a no-op
|
17
|
+
- Detaches the default rails log subscribes for `ActionController` and
|
18
|
+
`ActionView`
|
19
|
+
- Attaches its own custom log subscribers for `ActionController` and
|
20
|
+
`ActionCable`
|
21
|
+
- Allows configuration to add custom data to logs
|
22
|
+
- provides a number of different formatters
|
23
|
+
|
24
|
+
## How Logjoy works
|
25
|
+
|
26
|
+
- no monkey patching anything
|
27
|
+
- Detaches the default Rails log subscribers for
|
28
|
+
- action controller
|
29
|
+
- action view
|
30
|
+
- action mailer
|
31
|
+
- active storage
|
32
|
+
- Attaches a new log subscriber for
|
33
|
+
- action_controller
|
34
|
+
- only provides JSON formatting
|
35
|
+
- allows configuration to add custom data to logs
|
36
|
+
|
37
|
+
## TL;DR
|
38
|
+
|
39
|
+
Logjoy is very similar to Lograge with a few key differences
|
40
|
+
|
41
|
+
- no monkeypatching
|
42
|
+
- no change to action cable logs
|
43
|
+
- only JSON formatting
|
44
|
+
|
45
|
+
Monkeypatching Rails is avoided because that makes the code harder to maintain.
|
46
|
+
|
47
|
+
As a result, Logjoy is not as aggressive about cleaning up certain default Rails logs such as
|
48
|
+
the request started logs:
|
49
|
+
|
50
|
+
> `Started GET "/" for ::1 at 2021-09-2900:25:00 -0400`
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Logjoy
|
2
|
+
|
3
|
+
Logjoy makes some changes to Rails default `ActiveSupport::LogSubscriber`s in order
|
4
|
+
to provide streamlined request logs for use in production.
|
5
|
+
|
6
|
+
The name is an homage to the [lograge gem](https://github.com/roidrage/lograge)
|
7
|
+
which is no longer maintained and which this gem is intended to replace.
|
8
|
+
|
9
|
+
See
|
10
|
+
[LOGRAGE_README](https://github.com/pathouse/logjoy/blob/main/LOGRAGE_README.md)
|
11
|
+
for more information about the differences between this gem and lograge.
|
12
|
+
|
13
|
+
```json
|
14
|
+
{
|
15
|
+
"controller": "PagesController",
|
16
|
+
"action": "index",
|
17
|
+
"format": "html",
|
18
|
+
"method": "GET",
|
19
|
+
"path": "/",
|
20
|
+
"status": 200,
|
21
|
+
"view_runtime": 123.456,
|
22
|
+
"db_runtime": 123.456,
|
23
|
+
"duration": 1234.567,
|
24
|
+
"params": {},
|
25
|
+
"request_id": "95cb397a-df23-4548-b641-ae8eef9d3a4e",
|
26
|
+
"event": "process_action.action_controller",
|
27
|
+
"allocations": 123456
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'logjoy'
|
37
|
+
```
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
|
41
|
+
$ bundle install
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Logjoy can be configured with the following options:
|
46
|
+
|
47
|
+
`config/initializers/logjoy.rb`
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
Rails.application.configure do |config|
|
51
|
+
config.logjoy.enabled = true
|
52
|
+
|
53
|
+
config.logjoy.customizer = CustomizerClass
|
54
|
+
# or
|
55
|
+
config.logjoy.customizer = ->(event) { ... }
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
The customizer configuration may be a class that implements a `.call` method, or a lambda.
|
60
|
+
The customizer will receive an `ActiveSupport::Notification` event for the
|
61
|
+
`process_action.action_controller` event.
|
62
|
+
It should return a hash that will be added to the log in a `:custom` field.
|
63
|
+
|
64
|
+
More documentation about this event can be found here:
|
65
|
+
https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
70
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
71
|
+
prompt that will allow you to experiment.
|
72
|
+
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
74
|
+
release a new version, update the version number in `version.rb`, and then run
|
75
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
76
|
+
git commits and the created tag, and push the `.gem` file to
|
77
|
+
[rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at
|
82
|
+
https://github.com/pathouse/logjoy. This project is intended to be a safe,
|
83
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
84
|
+
the [code of
|
85
|
+
conduct](https://github.com/[USERNAME]/logjoy/blob/master/CODE_OF_CONDUCT.md).
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [MIT
|
90
|
+
License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubocop/rake_task'
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'logjoy'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/log_subscriber'
|
4
|
+
require 'action_controller/base'
|
5
|
+
require 'action_controller/log_subscriber'
|
6
|
+
|
7
|
+
module Logjoy
|
8
|
+
module LogSubscribers
|
9
|
+
class ActionController < ActiveSupport::LogSubscriber
|
10
|
+
def process_action(event)
|
11
|
+
info do
|
12
|
+
payload = event.payload
|
13
|
+
|
14
|
+
log = payload.slice(:controller, :action, :format, :method, :path, :status)
|
15
|
+
log[:view_runtime] = rounded_ms(payload[:view_runtime])
|
16
|
+
log[:db_runtime] = rounded_ms(payload[:db_runtime])
|
17
|
+
log[:duration] = rounded_ms(event.duration)
|
18
|
+
log[:params] = cleanup_params(payload[:params])
|
19
|
+
log[:request_id] = payload[:request].request_id
|
20
|
+
log[:event] = event.name
|
21
|
+
log[:allocations] = event.allocations
|
22
|
+
log[:custom] = Logjoy.custom_fields(event) if Logjoy.customizer.present?
|
23
|
+
|
24
|
+
if log[:status].nil? && (exception_class_name = payload[:exception]&.first)
|
25
|
+
log[:exception] = exception_class_name
|
26
|
+
log[:status] = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
log.to_json
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def logger
|
34
|
+
::ActionController::Base.logger
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def rounded_ms(value)
|
40
|
+
return 'N/A' if value.nil?
|
41
|
+
|
42
|
+
value.round(3)
|
43
|
+
end
|
44
|
+
|
45
|
+
def cleanup_params(params)
|
46
|
+
params.except(*::ActionController::LogSubscriber::INTERNAL_PARAMS)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/ordered_options'
|
4
|
+
require 'rails/railtie'
|
5
|
+
|
6
|
+
module Logjoy
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
config.logjoy = ActiveSupport::OrderedOptions.new
|
9
|
+
|
10
|
+
config.after_initialize do |app|
|
11
|
+
Logjoy.set_customizer(app)
|
12
|
+
end
|
13
|
+
|
14
|
+
Logjoy::REPLACE_SUBSCRIBERS.each do |component|
|
15
|
+
config.after_initialize do |app|
|
16
|
+
Logjoy.detach_default_subscriber(app, component)
|
17
|
+
Logjoy.attach_subscriber(app, component)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Logjoy::DETACH_SUBSCRIBERS.each do |component|
|
22
|
+
config.after_initialize do |app|
|
23
|
+
Logjoy.detach_default_subscriber(app, component)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/logjoy.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_view/log_subscriber'
|
4
|
+
require 'action_controller/log_subscriber'
|
5
|
+
require 'action_mailer/log_subscriber'
|
6
|
+
require 'active_storage/log_subscriber'
|
7
|
+
|
8
|
+
require_relative 'logjoy/version'
|
9
|
+
require_relative 'logjoy/log_subscribers/action_controller'
|
10
|
+
|
11
|
+
module Logjoy
|
12
|
+
class Error < StandardError; end
|
13
|
+
module_function
|
14
|
+
|
15
|
+
mattr_accessor :customizer
|
16
|
+
|
17
|
+
def custom_fields(event)
|
18
|
+
return {} if customizer.nil?
|
19
|
+
|
20
|
+
customizer.call(event)
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_customizer(app)
|
24
|
+
return unless enabled?(app)
|
25
|
+
|
26
|
+
self.customizer = app.config.logjoy.customizer
|
27
|
+
end
|
28
|
+
|
29
|
+
REPLACE_SUBSCRIBERS = %i[action_controller].freeze
|
30
|
+
DETACH_SUBSCRIBERS = %i[action_view action_mailer active_storage].freeze
|
31
|
+
|
32
|
+
def detach_default_subscriber(app, component)
|
33
|
+
return unless enabled?(app)
|
34
|
+
|
35
|
+
default_subscriber(component).detach_from(component)
|
36
|
+
end
|
37
|
+
|
38
|
+
def attach_subscriber(app, component)
|
39
|
+
return unless enabled?(app)
|
40
|
+
|
41
|
+
logjoy_subscriber(component).attach_to(component)
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_subscriber(component)
|
45
|
+
"#{component.to_s.camelize}::LogSubscriber".constantize
|
46
|
+
end
|
47
|
+
|
48
|
+
def logjoy_subscriber(component)
|
49
|
+
"Logjoy::LogSubscribers::#{component.to_s.camelize}".constantize
|
50
|
+
end
|
51
|
+
|
52
|
+
def enabled?(app)
|
53
|
+
app.config.logjoy.enabled
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
require 'logjoy/railtie'
|
data/logjoy.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/logjoy/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'logjoy'
|
7
|
+
spec.version = Logjoy::VERSION
|
8
|
+
spec.authors = ['Pat McGee']
|
9
|
+
spec.email = ['patmcgee331@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Alternative set of LogSubscriber classes for Rails for more structured JSON logs'
|
12
|
+
spec.homepage = 'https://github.com/pathouse/logjoy'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'actionmailer', '~> 6'
|
28
|
+
spec.add_runtime_dependency 'actionpack', '~> 6'
|
29
|
+
spec.add_runtime_dependency 'actionview', '~> 6'
|
30
|
+
spec.add_runtime_dependency 'activestorage', '~> 6'
|
31
|
+
spec.add_runtime_dependency 'activesupport', '~> 6'
|
32
|
+
spec.add_runtime_dependency 'railties', '~> 6'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logjoy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat McGee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionmailer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionview
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activestorage
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '6'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: railties
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- patmcgee331@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".rubocop_todo.yml"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- LOGRAGE_README.md
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- lib/logjoy.rb
|
117
|
+
- lib/logjoy/log_subscribers/action_controller.rb
|
118
|
+
- lib/logjoy/railtie.rb
|
119
|
+
- lib/logjoy/version.rb
|
120
|
+
- logjoy.gemspec
|
121
|
+
homepage: https://github.com/pathouse/logjoy
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata:
|
125
|
+
homepage_uri: https://github.com/pathouse/logjoy
|
126
|
+
source_code_uri: https://github.com/pathouse/logjoy
|
127
|
+
changelog_uri: https://github.com/pathouse/logjoy/blob/main/CHANGELOG.md
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 2.4.0
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.1.4
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Alternative set of LogSubscriber classes for Rails for more structured JSON
|
147
|
+
logs
|
148
|
+
test_files: []
|