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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef1c163f606f4ff39547e838da0dead49bf4b3ec13824e17f97ab5bc43398e51
4
- data.tar.gz: d3344d8049afb40f20786739a945ac1706ad47f41bed08f6939d5a827d6ffb5c
3
+ metadata.gz: 1473ad9c6f6b63a7df1d13b6492ab037c3560e524aa4cf04e21d8331aa995c6f
4
+ data.tar.gz: 0d7180652480d0763120a818b1867d8940be2a7efdb2470032cd53d11ea6d625
5
5
  SHA512:
6
- metadata.gz: 1a1b5d286379fbdaa60f2dd0b81d6a8258ccff40706ce37dfdd9e16c9b135a31ef6e6048e1cc6ff9d22bc6fe9298ce1ee2f6ef6a6bd1a411af7e9349524d0344
7
- data.tar.gz: a7cf2a4837f14532ce79591b271eab83a3074e818657e44fc564221f74741d210fee001dd5464f27bfb0508c589bf5d2b1dbaa5cf74cc3cc8f42045cb9cb8f05
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, :path, :status)
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
 
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Logjoy
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.3'
5
5
  end
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.2.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-09-29 00:00:00.000000000 Z
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer