epilog 0.8.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 034ff527f27b5bc41a2d055b3224afb73fdadc95e7c0b1fd2df86c86cc71db02
4
- data.tar.gz: '010087e2788e3f9e5e3a2550ab3f5dc415924bbdd777846483b650786c6f8547'
3
+ metadata.gz: e0f45daf54940c2e7449ae321341278f537f642429728a646339d0ad057ff933
4
+ data.tar.gz: ffade4ca680a3908a8d9c6c5912647881420d217dfeffbfd4e843195df62e30c
5
5
  SHA512:
6
- metadata.gz: 7692d82f84ac6416fc7c1ae6ef98e2b67b15e3033799c567c2899b7684507cfd06a30133fbdb3d35b5a0184e7f4af1c8c95da7345db7a5e96caae121b2c29163
7
- data.tar.gz: 49e8232ee95b2435377b80eae597f39d0e95e82b7e848cd4619814cefbf3bdccff4b5b8e224b7166291675aec40b963d244a29abbfb4f516ef7a6d128db4f58f
6
+ metadata.gz: 60d208d4fa4e7bf3b8948e2888bda13ed4cf052bb23719f9fcc8e510166a8486eb0318b668377b388e732b932ba756a76aa6d4295fbda517c44bb506c6b0a381
7
+ data.tar.gz: dbe0e0a0d5dcd03b20fa0ef1ea87241745dba275e2297d9cba1cd34135b30bc602bf9aac1e9994070696bcd36b9e2b6343d8dff9dadc658285fe95a9461c9d16
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.2
4
+
5
+ - Fix double log issue in Rails 7.1+
6
+
7
+ ## 0.9.1
8
+
9
+ - Remove Rails 8 from CI
10
+
11
+ ## 0.9.0
12
+
13
+ - Add support for Rails 7.0 and Rails 7.1
14
+ - Drop support for Rails < 7.0
15
+ - Drop support for Ruby < 3.3
16
+ - Update dev and runtime dependencies
17
+
3
18
  ## 0.8.0
4
19
 
5
20
  - Update license to MIT [#19](https://github.com/nullscreen/epilog/pull/19)
@@ -13,7 +13,7 @@ module Epilog
13
13
  attr_reader :blacklist
14
14
 
15
15
  def initialize(blacklist = DEFAULT_BLACKLIST)
16
- @blacklist = blacklist.map { |b| [b.to_s.downcase, nil] }.to_h
16
+ @blacklist = blacklist.to_h { |b| [b.to_s.downcase, nil] }
17
17
  super()
18
18
  end
19
19
 
@@ -8,9 +8,9 @@ module Epilog
8
8
  def filter_parameters
9
9
  return @filter_parameters if @filter_parameters
10
10
 
11
- filtered = ::Rails.application.config.filter_parameters.map do |p|
11
+ filtered = ::Rails.application.config.filter_parameters.to_h do |p|
12
12
  [p.to_s.downcase, true]
13
- end.to_h
13
+ end
14
14
 
15
15
  @filter_parameters = filtered if ::Rails.initialized?
16
16
  filtered
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Epilog
4
4
  class MockLogger < ::Logger
5
- def initialize(**options)
6
- super(nil, **options)
5
+ def initialize(**)
6
+ super(nil, **)
7
7
  reset
8
8
  end
9
9
 
@@ -88,7 +88,7 @@ module Epilog
88
88
  info do
89
89
  {
90
90
  message: response_string(event),
91
- request: request,
91
+ request:,
92
92
  response: response_hash(event),
93
93
  metrics: process_metrics(event.payload[:metrics]
94
94
  .merge(request_runtime: event.duration.round(2)))
@@ -158,7 +158,7 @@ module Epilog
158
158
 
159
159
  def basic_message(event, message)
160
160
  {
161
- message: message,
161
+ message:,
162
162
  metrics: process_metrics(duration: event.duration)
163
163
  }
164
164
  end
@@ -19,7 +19,7 @@ module Epilog
19
19
 
20
20
  def hash(event, message)
21
21
  {
22
- message: message,
22
+ message:,
23
23
  template: fix_path(event.payload[:identifier]),
24
24
  layout: fix_path(event.payload[:layout]),
25
25
  metrics: {
@@ -75,7 +75,7 @@ module Epilog
75
75
 
76
76
  def event_hash(message, event)
77
77
  {
78
- message: message,
78
+ message:,
79
79
  job: job_hash(event.payload[:job]),
80
80
  adapter: adapter_name(event.payload[:adapter])
81
81
  }
@@ -6,7 +6,7 @@ module Epilog
6
6
  IGNORE_PAYLOAD_NAMES = %w[SCHEMA EXPLAIN].freeze
7
7
 
8
8
  def sql(event)
9
- ActiveRecord::LogSubscriber.runtime += event.duration
9
+ ActiveRecord::RuntimeRegistry.sql_runtime = (ActiveRecord::RuntimeRegistry.sql_runtime || 0) + event.duration
10
10
 
11
11
  return unless logger.debug?
12
12
 
@@ -5,29 +5,27 @@ module Epilog
5
5
  def process_action(*)
6
6
  epilog_instrument('request_received')
7
7
  epilog_instrument('process_request') do |payload|
8
- begin
9
- super
10
- ensure
11
- payload[:response] = response
12
- payload[:metrics] = epilog_metrics
13
- end
8
+ super
9
+ ensure
10
+ payload[:response] = response
11
+ payload[:metrics] = epilog_metrics
14
12
  end
15
13
  end
16
14
 
17
15
  private
18
16
 
19
- def epilog_instrument(name, &block)
17
+ def epilog_instrument(name, &)
20
18
  ActiveSupport::Notifications.instrument(
21
19
  "#{name}.action_controller",
22
20
  epilog_payload,
23
- &block
21
+ &
24
22
  )
25
23
  end
26
24
 
27
25
  def epilog_payload
28
26
  {
29
- request: request,
30
- response: response,
27
+ request:,
28
+ response:,
31
29
  controller: self.class.name,
32
30
  action: action_name,
33
31
  context: epilog_context
@@ -37,7 +35,7 @@ module Epilog
37
35
  def epilog_metrics
38
36
  {
39
37
  db_runtime: try(:db_runtime),
40
- view_runtime: view_runtime
38
+ view_runtime:
41
39
  }
42
40
  end
43
41
 
@@ -1,16 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActiveSupport
4
- class Logger
5
- # Rails uses this method to attach additional loggers to the main
6
- # Rails.logger object when using the rails console or server. This results
7
- # in extra unformatted log output in those cases. Prevent that by
8
- # overriding the method with a stub. Examples can be found in
9
- #
10
- # - railties/lib/rails/commands/server.rb
11
- # - active_record/lib/active_record/railtie.rb
12
- def self.broadcast(*_args)
13
- Module.new
3
+ # For Rails 7.1+, the broadcast_to patch is applied in the railtie's
4
+ # after_initialize block (see railtie.rb) to ensure the BroadcastLogger
5
+ # class is fully defined before we patch it.
6
+ if ::Rails.gem_version < Gem::Version.new('7.1')
7
+ module ActiveSupport
8
+ class Logger
9
+ # Rails uses this method to attach additional loggers to the main
10
+ # Rails.logger object when using the rails console or server. This results
11
+ # in extra unformatted log output in those cases. Prevent that by
12
+ # overriding the method with a stub. Examples can be found in
13
+ #
14
+ # - railties/lib/rails/commands/server.rb
15
+ # - active_record/lib/active_record/railtie.rb
16
+ def self.broadcast(*_args)
17
+ Module.new
18
+ end
14
19
  end
15
20
  end
16
21
  end
@@ -3,10 +3,13 @@
3
3
  module Epilog
4
4
  module EventDelegateExt
5
5
  # Rails has no public API to determine the delegate for an event
6
- # object. Add this method to allow checking if the delegate matches
7
- # a given object.
8
- def delegates_to?(delegate)
9
- @delegate == delegate
6
+ # object. Add these methods to allow checking the delegate.
7
+ def delegate
8
+ @delegate
9
+ end
10
+
11
+ def delegates_to?(other)
12
+ @delegate == other
10
13
  end
11
14
  end
12
15
  end
@@ -44,8 +44,6 @@ module Epilog
44
44
  ]
45
45
 
46
46
  initializer 'epilog.configure' do |app|
47
- disable_rails_defaults
48
-
49
47
  ::Rails.logger ||= Logger.new($stdout)
50
48
 
51
49
  app.config.epilog.subscriptions.each do |namespace|
@@ -57,28 +55,70 @@ module Epilog
57
55
  end
58
56
  end
59
57
 
60
- private
58
+ # In Rails 7.1+, the server, console, and other components (like Sidekiq)
59
+ # call Rails.logger.broadcast_to() to add additional log destinations.
60
+ # This causes duplicate log lines and can lead to blocks being executed
61
+ # multiple times (via BroadcastLogger's method_missing delegation).
62
+ #
63
+ # This initializer runs AFTER :initialize_logger (which wraps the logger
64
+ # in a BroadcastLogger) but BEFORE any after_initialize hooks (where
65
+ # Sidekiq and others add their loggers). This ensures the no-op is in
66
+ # place before anyone tries to call broadcast_to.
67
+ initializer 'epilog.prevent_broadcast', after: :initialize_logger do
68
+ if ::Rails.gem_version >= Gem::Version.new('7.1') && ::Rails.logger
69
+ ::Rails.logger.define_singleton_method(:broadcast_to) { |*| nil }
70
+ end
71
+ end
72
+
73
+ # In Rails 7.1+, ActionView::LogSubscriber::Start are attached late
74
+ # in the initialization process, so we need to disable them after
75
+ # initialization completes
76
+ config.after_initialize do
77
+ disable_rails_defaults
78
+ end
79
+
80
+ class << self
81
+ private
61
82
 
62
- def disable_rails_defaults
63
- blacklisted_subscribers.each do |subscriber|
64
- subscriber.patterns.each do |pattern|
65
- unsubscribe_listeners(subscriber, pattern)
83
+ def disable_rails_defaults
84
+ blacklisted_subscribers.each do |subscriber|
85
+ subscriber.patterns.each do |pattern|
86
+ unsubscribe_listeners(subscriber, pattern)
87
+ end
66
88
  end
89
+
90
+ # Rails 7.1 adds ActionView::LogSubscriber::Start which subscribes
91
+ # separately and logs "Rendering..." messages at the start of rendering
92
+ # see https://github.com/rails/rails/commit/9c58a54702b038b9acebdb3efa85c26156ff1987#diff-fd389a9f74e2259b56015e3f8d15a5ce33c093045dd4cb354e82d6d81fe9b06aR98-R99
93
+ unsubscribe_action_view_start_listeners
67
94
  end
68
- end
69
95
 
70
- def unsubscribe_listeners(subscriber, pattern)
71
- notifier = ActiveSupport::Notifications.notifier
72
- notifier.listeners_for(Array.wrap(pattern).first).each do |listener|
73
- if listener.delegates_to?(subscriber)
74
- ActiveSupport::Notifications.unsubscribe(listener)
96
+ def unsubscribe_listeners(subscriber, pattern)
97
+ notifier = ActiveSupport::Notifications.notifier
98
+ notifier.listeners_for(Array.wrap(pattern).first).each do |listener|
99
+ if listener.delegates_to?(subscriber)
100
+ ActiveSupport::Notifications.unsubscribe(listener)
101
+ end
75
102
  end
76
103
  end
77
- end
78
104
 
79
- def blacklisted_subscribers
80
- ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
81
- SUBSCRIBER_BLACKLIST.include?(subscriber.class)
105
+ def unsubscribe_action_view_start_listeners
106
+ return unless defined?(ActionView::LogSubscriber::Start)
107
+
108
+ notifier = ActiveSupport::Notifications.notifier
109
+ %w[render_template.action_view render_layout.action_view].each do |pattern|
110
+ notifier.listeners_for(pattern).each do |listener|
111
+ if listener.delegate.is_a?(ActionView::LogSubscriber::Start)
112
+ ActiveSupport::Notifications.unsubscribe(listener)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ def blacklisted_subscribers
119
+ ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
120
+ SUBSCRIBER_BLACKLIST.include?(subscriber.class)
121
+ end
82
122
  end
83
123
  end
84
124
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Epilog
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.2'
5
5
 
6
6
  def self.version
7
7
  Gem::Version.new(VERSION)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epilog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Howard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-10 00:00:00.000000000 Z
11
+ date: 2026-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: combustion
@@ -31,9 +31,6 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.2'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '7'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,9 +38,6 @@ dependencies:
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
40
  version: '4.2'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '7'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rspec
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -62,31 +56,31 @@ dependencies:
62
56
  name: rspec-rails
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - "~>"
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
- version: '5.1'
61
+ version: '7.0'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
- - - "~>"
66
+ - - ">="
73
67
  - !ruby/object:Gem::Version
74
- version: '5.1'
68
+ version: '7.0'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: sqlite3
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
- - - "~>"
73
+ - - ">="
80
74
  - !ruby/object:Gem::Version
81
- version: '1.3'
75
+ version: '1.4'
82
76
  type: :development
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
- - - "~>"
80
+ - - ">="
87
81
  - !ruby/object:Gem::Version
88
- version: '1.3'
89
- description:
82
+ version: '1.4'
83
+ description:
90
84
  email:
91
85
  - jmhoward0@gmail.com
92
86
  executables: []
@@ -126,9 +120,9 @@ licenses:
126
120
  - MIT
127
121
  metadata:
128
122
  changelog_uri: https://github.com/nullscreen/epilog/blob/main/CHANGELOG.md
129
- documentation_uri: https://www.rubydoc.info/gems/epilog/0.8.0
123
+ documentation_uri: https://www.rubydoc.info/gems/epilog/0.9.2
130
124
  rubygems_mfa_required: 'true'
131
- post_install_message:
125
+ post_install_message:
132
126
  rdoc_options: []
133
127
  require_paths:
134
128
  - lib
@@ -136,15 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
130
  requirements:
137
131
  - - ">="
138
132
  - !ruby/object:Gem::Version
139
- version: '2.3'
133
+ version: '3.3'
140
134
  required_rubygems_version: !ruby/object:Gem::Requirement
141
135
  requirements:
142
136
  - - ">="
143
137
  - !ruby/object:Gem::Version
144
138
  version: '0'
145
139
  requirements: []
146
- rubygems_version: 3.1.2
147
- signing_key:
140
+ rubygems_version: 3.4.20
141
+ signing_key:
148
142
  specification_version: 4
149
143
  summary: A JSON logger with Rails support
150
144
  test_files: []