logjoy 0.1.0 → 0.3.2

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: 90661f240bf5c1fb3c326ecf2f95e7c5d1ed9049c71f58c8f982b4e16eba5903
4
- data.tar.gz: 07e1678a7a947eba4aa63edee0914759026a0e34525095c8e4f285d794ed167e
3
+ metadata.gz: 11c513fbdb9b797a2d28791aa614408fc4cf714050b8f59283ccdcdb6fbcb6e7
4
+ data.tar.gz: 79215d5fe4b13fdc55fb82d2d62613c2c4bbc4ca3bf131160726918003d928de
5
5
  SHA512:
6
- metadata.gz: 0e9ad2e6fd27e47be5f9f7808de85ba775a0c2e92400b1cb2ef7683ba68b88793440bcead1c5235375c9751cf6657bf3232f7ac5b5b48084e4721b500f40378b
7
- data.tar.gz: 298bd247f702952959f06bbdb85bca43e7c6c174da7352914c79048661d661c39c981172bb9ab477be096d3fccc6dbd6ffb883e705d872b84acfd1e42c862065
6
+ metadata.gz: 67c25f433f4cc5bd88652ebfcbcbae71e9dc27c3ebc9b295b1dcc4d775a65132a63fa7de58b9a0ffe33b7630f29c037f10d17b755642ea8d4977da724adaa741
7
+ data.tar.gz: b88dfefcbea5ae84b29a11121ce6ec328c92f0cd4b40ec258824089a4e958d960fce2688a4ca74b4bb1d997be416b160f775568f609439a68cc083d4ca800ce7
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
@@ -8,10 +8,13 @@ module Logjoy
8
8
  module LogSubscribers
9
9
  class ActionController < ActiveSupport::LogSubscriber
10
10
  def process_action(event)
11
+ return if ignore_event?(event)
12
+
11
13
  info do
12
14
  payload = event.payload
13
15
 
14
- log = payload.slice(:controller, :action, :format, :method, :path, :status)
16
+ log = payload.slice(:controller, :action, :format, :method, :status)
17
+ log[:path] = strip_query(payload[:path])
15
18
  log[:view_runtime] = rounded_ms(payload[:view_runtime])
16
19
  log[:db_runtime] = rounded_ms(payload[:db_runtime])
17
20
  log[:duration] = rounded_ms(event.duration)
@@ -19,14 +22,13 @@ module Logjoy
19
22
  log[:request_id] = payload[:request].request_id
20
23
  log[:event] = event.name
21
24
  log[:allocations] = event.allocations
22
- log[:custom] = Logjoy.custom_fields(event) if Logjoy.customizer.present?
23
25
 
24
26
  if log[:status].nil? && (exception_class_name = payload[:exception]&.first)
25
27
  log[:exception] = exception_class_name
26
28
  log[:status] = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
27
29
  end
28
30
 
29
- log.to_json
31
+ log.merge(Logjoy.custom_fields(event)).to_json
30
32
  end
31
33
  end
32
34
 
@@ -36,6 +38,15 @@ module Logjoy
36
38
 
37
39
  private
38
40
 
41
+ def strip_query(path_with_query)
42
+ uri = URI.parse(path_with_query)
43
+ uri.path
44
+ end
45
+
46
+ def ignore_event?(event)
47
+ Logjoy.filters.include?(event.payload[:path])
48
+ end
49
+
39
50
  def rounded_ms(value)
40
51
  return 'N/A' if value.nil?
41
52
 
@@ -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.1.0'
4
+ VERSION = '0.3.2'
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.1.0
4
+ version: 0.3.2
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-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer