logjoy 0.2.0 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/logjoy/log_subscribers/action_controller.rb +13 -2
- data/lib/logjoy/railtie.rb +4 -0
- data/lib/logjoy/version.rb +1 -1
- data/lib/logjoy.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1473ad9c6f6b63a7df1d13b6492ab037c3560e524aa4cf04e21d8331aa995c6f
|
4
|
+
data.tar.gz: 0d7180652480d0763120a818b1867d8940be2a7efdb2470032cd53d11ea6d625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aae9b5331fc525afec2aa46130467c9d9cc7d036534bced3ef3d3c94d53a33e07390c2d2853b750c3f561a21e4529eeefaaee5f3fe15a7e53db121186eb9bee2
|
7
|
+
data.tar.gz: 3dc63a6b4d9b9ab10fa6a9dad2a8ac2da3acd6d7ddb79b4737255cd2dd6a3cc1d2525101a07a5698baea35c693cd39bc06747895504d87c56549c6a8c51d61db
|
data/README.md
CHANGED
@@ -53,6 +53,8 @@ Rails.application.configure do |config|
|
|
53
53
|
config.logjoy.customizer = CustomizerClass
|
54
54
|
# or
|
55
55
|
config.logjoy.customizer = ->(event) { ... }
|
56
|
+
|
57
|
+
config.logjoy.filters = ['/health_check']
|
56
58
|
end
|
57
59
|
```
|
58
60
|
|
@@ -64,6 +66,9 @@ It should return a hash that will be added to the log in a `:custom` field.
|
|
64
66
|
More documentation about this event can be found here:
|
65
67
|
https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller
|
66
68
|
|
69
|
+
The filters configuration can be used to ignore requests with the given path to
|
70
|
+
reduce log noise from things like health checks.
|
71
|
+
|
67
72
|
## Development
|
68
73
|
|
69
74
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
@@ -1,17 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/log_subscriber'
|
4
|
-
require 'action_controller/base'
|
5
4
|
require 'action_controller/log_subscriber'
|
6
5
|
|
7
6
|
module Logjoy
|
8
7
|
module LogSubscribers
|
9
8
|
class ActionController < ActiveSupport::LogSubscriber
|
10
9
|
def process_action(event)
|
10
|
+
return if ignore_event?(event)
|
11
|
+
|
11
12
|
info do
|
12
13
|
payload = event.payload
|
13
14
|
|
14
|
-
log = payload.slice(:controller, :action, :format, :method, :
|
15
|
+
log = payload.slice(:controller, :action, :format, :method, :status)
|
16
|
+
log[:path] = strip_query(payload[:path])
|
15
17
|
log[:view_runtime] = rounded_ms(payload[:view_runtime])
|
16
18
|
log[:db_runtime] = rounded_ms(payload[:db_runtime])
|
17
19
|
log[:duration] = rounded_ms(event.duration)
|
@@ -35,6 +37,15 @@ module Logjoy
|
|
35
37
|
|
36
38
|
private
|
37
39
|
|
40
|
+
def strip_query(path_with_query)
|
41
|
+
uri = URI.parse(path_with_query)
|
42
|
+
uri.path
|
43
|
+
end
|
44
|
+
|
45
|
+
def ignore_event?(event)
|
46
|
+
Logjoy.filters.include?(event.payload[:path])
|
47
|
+
end
|
48
|
+
|
38
49
|
def rounded_ms(value)
|
39
50
|
return 'N/A' if value.nil?
|
40
51
|
|
data/lib/logjoy/railtie.rb
CHANGED
@@ -11,6 +11,10 @@ module Logjoy
|
|
11
11
|
Logjoy.set_customizer(app)
|
12
12
|
end
|
13
13
|
|
14
|
+
config.after_initialize do |app|
|
15
|
+
Logjoy.set_path_filters(app)
|
16
|
+
end
|
17
|
+
|
14
18
|
Logjoy::REPLACE_SUBSCRIBERS.each do |component|
|
15
19
|
config.after_initialize do |app|
|
16
20
|
Logjoy.detach_default_subscriber(app, component)
|
data/lib/logjoy/version.rb
CHANGED
data/lib/logjoy.rb
CHANGED
@@ -4,6 +4,7 @@ require 'action_view/log_subscriber'
|
|
4
4
|
require 'action_controller/log_subscriber'
|
5
5
|
require 'action_mailer/log_subscriber'
|
6
6
|
require 'active_storage/log_subscriber'
|
7
|
+
require 'active_support/core_ext/string/inflections'
|
7
8
|
|
8
9
|
require_relative 'logjoy/version'
|
9
10
|
require_relative 'logjoy/log_subscribers/action_controller'
|
@@ -12,7 +13,8 @@ module Logjoy
|
|
12
13
|
class Error < StandardError; end
|
13
14
|
module_function
|
14
15
|
|
15
|
-
mattr_accessor :customizer
|
16
|
+
mattr_accessor :customizer, :filters
|
17
|
+
self.filters = []
|
16
18
|
|
17
19
|
def custom_fields(event)
|
18
20
|
return {} if customizer.nil?
|
@@ -26,6 +28,12 @@ module Logjoy
|
|
26
28
|
self.customizer = app.config.logjoy.customizer
|
27
29
|
end
|
28
30
|
|
31
|
+
def set_path_filters(app)
|
32
|
+
return unless enabled?(app)
|
33
|
+
|
34
|
+
self.filters = app.config.logjoy.filters || []
|
35
|
+
end
|
36
|
+
|
29
37
|
REPLACE_SUBSCRIBERS = %i[action_controller].freeze
|
30
38
|
DETACH_SUBSCRIBERS = %i[action_view action_mailer active_storage].freeze
|
31
39
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjoy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat McGee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|