epilog 0.8.0 → 0.9.1

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: 7ac4b15922bc0e1c3c38b10294d3f77c3a6c6ae3f5b2af5a619e4adcfdc6e048
4
+ data.tar.gz: 02d8a2ae1e715a3a3d7f1311eb9ba663482741fbce231b3a9b30096fd1eb94f6
5
5
  SHA512:
6
- metadata.gz: 7692d82f84ac6416fc7c1ae6ef98e2b67b15e3033799c567c2899b7684507cfd06a30133fbdb3d35b5a0184e7f4af1c8c95da7345db7a5e96caae121b2c29163
7
- data.tar.gz: 49e8232ee95b2435377b80eae597f39d0e95e82b7e848cd4619814cefbf3bdccff4b5b8e224b7166291675aec40b963d244a29abbfb4f516ef7a6d128db4f58f
6
+ metadata.gz: c24a853903514771cc7847d7c9f7a08ae48619e3478711a94dc8b1d698465aaa581731037fc4553ff8e9f382103bb0ed1a3f89879a503a3cb7d4fa3cdda8f4e1
7
+ data.tar.gz: '0190bdd527b8c2ca361d0837443c3e6f411809f8f5a9ce1c48bfc2f4cfe61a254fa5e0c269aaaf116bf504ef87b96b142fd69abb42d486f8cb7e48ed12bc9174'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.1
4
+
5
+ - Remove Rails 8 from CI
6
+
7
+ ## 0.9.0
8
+
9
+ - Add support for Rails 7.0 and Rails 7.1
10
+ - Drop support for Rails < 7.0
11
+ - Drop support for Ruby < 3.3
12
+ - Update dev and runtime dependencies
13
+
3
14
  ## 0.8.0
4
15
 
5
16
  - 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,71 @@ module Epilog
57
55
  end
58
56
  end
59
57
 
60
- private
58
+ # In Rails 7.1+, ActionView::LogSubscriber::Start are attached late
59
+ # in the initialization process, so we need to disable them after
60
+ # initialization completes
61
+ config.after_initialize do
62
+ disable_rails_defaults
63
+ prevent_double_logs_from_broadcast
64
+ end
65
+
66
+ class << self
67
+ private
61
68
 
62
- def disable_rails_defaults
63
- blacklisted_subscribers.each do |subscriber|
64
- subscriber.patterns.each do |pattern|
65
- unsubscribe_listeners(subscriber, pattern)
69
+ def disable_rails_defaults
70
+ blacklisted_subscribers.each do |subscriber|
71
+ subscriber.patterns.each do |pattern|
72
+ unsubscribe_listeners(subscriber, pattern)
73
+ end
66
74
  end
75
+
76
+ # Rails 7.1 adds ActionView::LogSubscriber::Start which subscribes
77
+ # separately and logs "Rendering..." messages at the start of rendering
78
+ # see https://github.com/rails/rails/commit/9c58a54702b038b9acebdb3efa85c26156ff1987#diff-fd389a9f74e2259b56015e3f8d15a5ce33c093045dd4cb354e82d6d81fe9b06aR98-R99
79
+ unsubscribe_action_view_start_listeners
67
80
  end
68
- end
69
81
 
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)
82
+ def unsubscribe_listeners(subscriber, pattern)
83
+ notifier = ActiveSupport::Notifications.notifier
84
+ notifier.listeners_for(Array.wrap(pattern).first).each do |listener|
85
+ if listener.delegates_to?(subscriber)
86
+ ActiveSupport::Notifications.unsubscribe(listener)
87
+ end
75
88
  end
76
89
  end
77
- end
78
90
 
79
- def blacklisted_subscribers
80
- ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
81
- SUBSCRIBER_BLACKLIST.include?(subscriber.class)
91
+ def unsubscribe_action_view_start_listeners
92
+ return unless defined?(ActionView::LogSubscriber::Start)
93
+
94
+ notifier = ActiveSupport::Notifications.notifier
95
+ %w[render_template.action_view render_layout.action_view].each do |pattern|
96
+ notifier.listeners_for(pattern).each do |listener|
97
+ if listener.delegate.is_a?(ActionView::LogSubscriber::Start)
98
+ ActiveSupport::Notifications.unsubscribe(listener)
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # In Rails 7.1+, the server and console call Rails.logger.broadcast_to(console)
105
+ # which adds a second logger and causes every log line to appear twice
106
+ # (e.g. custom format + default Logger format). Override broadcast_to with
107
+ # a no-op to prevent adding duplicate destinations.
108
+ #
109
+ # This must be done in after_initialize (not at require time) because:
110
+ # 1. Rails wraps the logger in a BroadcastLogger during bootstrap
111
+ # 2. We need to override the instance method on the actual Rails.logger
112
+ def prevent_double_logs_from_broadcast
113
+ return if ::Rails.gem_version < Gem::Version.new('7.1')
114
+ return unless ::Rails.logger
115
+
116
+ ::Rails.logger.define_singleton_method(:broadcast_to) { |*| nil }
117
+ end
118
+
119
+ def blacklisted_subscribers
120
+ ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
121
+ SUBSCRIBER_BLACKLIST.include?(subscriber.class)
122
+ end
82
123
  end
83
124
  end
84
125
  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.1'
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.1
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-10 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.1
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: []