rails_semantic_logger 5.1.0 → 5.2.0

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: f0d257eeb6faedaba38caba805893dc4c269dfaf0b1b0f5cc496d54e3bc3f6ad
4
- data.tar.gz: 5ae1af5ac5514a6fd84f70f4b0d13232791f942b3fead595a082ae15c1258893
3
+ metadata.gz: '08056406dee88f7c5eb0d29107d9d82b95487cf913ace9a6dd292c49641f58c4'
4
+ data.tar.gz: 5dfdb7970f4baf88676218aa9a0778245957c094dc1ee7103e7940c456a54e06
5
5
  SHA512:
6
- metadata.gz: 7a79e69e2a466f8a0f414b21e3890118eac262c7bb2983a91cfac547fc04f3cb91535bde3aa1ff611d57a1b5a6e56d7ba885f8177f3d0a0777682de844ba2b9e
7
- data.tar.gz: cc0fb18514ef84ee7e3ec270a70bf155aa54e6f71e0fffe59f0492fb712d5dab64ec27c42ab69afaccde1259aeb75913319d1fbc07f70bea7938e3fe231ef8aa
6
+ metadata.gz: e138fdae60edf8a40b1e0b57d4b351bc0069b48550f0ecd0ee443ef8bbb154984c8923a07632d441cf154b39f7777e266073254f6cd57bd6bf83c26dd59c5b63
7
+ data.tar.gz: 5e7e1e27aded0d3a1731cab0f756dfada2d11dcf1f2a756bd41ecfa912c44f9931649df0a2e56f32d21328a64f22db1a9f97c02c6ac939f17974342f4805c7d8
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rails Semantic Logger
2
2
  [![Gem Version](https://img.shields.io/gem/v/rails_semantic_logger.svg)](https://rubygems.org/gems/rails_semantic_logger) [![Build Status](https://github.com/reidmorrison/rails_semantic_logger/workflows/build/badge.svg)](https://github.com/reidmorrison/rails_semantic_logger/actions?query=workflow%3Abuild) [![Downloads](https://img.shields.io/gem/dt/rails_semantic_logger.svg)](https://rubygems.org/gems/rails_semantic_logger) [![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](http://opensource.org/licenses/Apache-2.0) ![](https://img.shields.io/badge/status-Production%20Ready-blue.svg)
3
3
 
4
- Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](https://logger.rocketjob.io/), so that Rails, your application code, and many common gems all log through structured logging instead of plain text.
4
+ Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](https://logger.reidmorrison.com/), so that Rails, your application code, and many common gems all log through structured logging instead of plain text.
5
5
 
6
6
  When any large Rails application is deployed to production one of the first steps is to move to centralized logging, so that logs can be viewed and searched from a central location. That quickly falls apart when consuming human readable text logs:
7
7
 
@@ -67,17 +67,17 @@ end
67
67
 
68
68
  Because declaring an appender replaces the default file appender, JSON to stdout becomes the only destination, exactly what a container platform wants. Once logs are emitted as structured JSON, a centralized logging system can parse each field, including the nested `payload` and any `metric` data, into a searchable hierarchy, so you can build searches, alerts, and dashboards against well-defined fields instead of brittle text matching.
69
69
 
70
- See [Configuring appenders](https://logger.rocketjob.io/rails#configuring-where-logs-go-the-appenders-block) for the full guide, including formatters, third-party destinations, the [container platform recipe](https://logger.rocketjob.io/rails#production-on-a-container-platform-docker-kubernetes-heroku), tuning what Rails logs, and worked examples of querying the JSON.
70
+ See [Configuring appenders](https://logger.reidmorrison.com/rails#configuring-where-logs-go-the-appenders-block) for the full guide, including formatters, third-party destinations, the [container platform recipe](https://logger.reidmorrison.com/rails#production-on-a-container-platform-docker-kubernetes-heroku), tuning what Rails logs, and worked examples of querying the JSON.
71
71
 
72
72
  ## Documentation
73
73
 
74
- For complete documentation see: https://logger.rocketjob.io/rails
74
+ For complete documentation see: https://logger.reidmorrison.com/rails
75
75
 
76
76
  ## Upgrading
77
77
 
78
78
  The way appenders (log destinations) are configured changed in v5. See the
79
- [v4 to v5 migration guide](https://logger.rocketjob.io/rails#migrating-from-v4-to-v5) for the
80
- before/after mapping, and [Migrating from earlier versions](https://logger.rocketjob.io/rails#migrating-from-earlier-versions)
79
+ [v4 to v5 migration guide](https://logger.reidmorrison.com/rails#migrating-from-v4-to-v5) for the
80
+ before/after mapping, and [Migrating from earlier versions](https://logger.reidmorrison.com/rails#migrating-from-earlier-versions)
81
81
  for older releases.
82
82
 
83
83
  ## New Versions of Rails, etc.
@@ -25,6 +25,27 @@ module RailsSemanticLogger
25
25
  # insert itself above the configured rails logger to add support for its
26
26
  # additional features
27
27
 
28
+ # Register this gem's deprecator with the application so that the standard Rails
29
+ # deprecation settings govern it: `config.active_support.report_deprecations`,
30
+ # `config.active_support.deprecation`, and
31
+ # `Rails.application.deprecators[:rails_semantic_logger]`. Rails' own
32
+ # `active_support.deprecation_behavior` initializer only reaches deprecators in
33
+ # that collection.
34
+ #
35
+ # Runs before the environment file is read so that an application can also reach
36
+ # the deprecator by name from `config/environments/*.rb`.
37
+ initializer "rails_semantic_logger.deprecator", before: :load_environment_config do |app|
38
+ app.deprecators[:rails_semantic_logger] = RailsSemanticLogger.deprecator
39
+ end
40
+
41
+ # The deprecated appender options are set from `config/application.rb` and
42
+ # `config/environments/*.rb`, which Rails reads before it applies the deprecation
43
+ # settings above, so their warnings are recorded rather than emitted. Now that
44
+ # the settings are in place, emit them.
45
+ initializer "rails_semantic_logger.flush_deprecations", after: "active_support.deprecation_behavior" do |app|
46
+ app.config.rails_semantic_logger.flush_deprecations!
47
+ end
48
+
28
49
  # Replace Rails logger initializer
29
50
  Rails::Application::Bootstrap.initializers.delete_if { |i| i.name == :initialize_logger }
30
51
 
@@ -1,70 +1,81 @@
1
- require "action_cable/connection/tagged_logger_proxy"
2
-
3
- # Upstream source (identical across supported versions):
1
+ # Upstream source (identical across supported versions, only the namespace differs):
4
2
  # https://github.com/rails/rails/blob/v7.2.2/actioncable/lib/action_cable/connection/tagged_logger_proxy.rb
5
3
  # https://github.com/rails/rails/blob/v8.0.2/actioncable/lib/action_cable/connection/tagged_logger_proxy.rb
6
4
  # https://github.com/rails/rails/blob/v8.1.3/actioncable/lib/action_cable/connection/tagged_logger_proxy.rb
7
- module ActionCable
8
- module Connection
9
- class TaggedLoggerProxy
10
- # Mirrors upstream #tag, including the `respond_to?(:tagged)` guard so a
11
- # target logger without tagging support (e.g. when handed a non-tagged
12
- # ActiveRecord::Base.logger by the worker pool) simply yields. Diverges in
13
- # one place: upstream reads the already-applied tags via
14
- # `logger.formatter.current_tags` (ActiveSupport::TaggedLogging), but
15
- # Semantic Logger exposes them via `#tags`, so resolve from whichever the
16
- # target logger supports. See #220.
17
- def tag(logger, &)
18
- if logger.respond_to?(:tagged)
19
- current_tags = tags - applied_tags_for(logger)
20
- logger.tagged(*current_tags, &)
21
- else
22
- yield
23
- end
5
+ # https://github.com/rails/rails/blob/main/actioncable/lib/action_cable/server/tagged_logger_proxy.rb
6
+ module RailsSemanticLogger
7
+ module ActionCable
8
+ # Rails 8.2 moved the proxy from ActionCable::Connection to ActionCable::Server, as part of
9
+ # the ActionCable::Server::Socket refactor, without leaving a back-compat alias behind.
10
+ # Resolve whichever constant this version of ActionCable ships rather than hard-coding a
11
+ # namespace, so that a `require` of the old path cannot fail the app's boot. See #326.
12
+ TaggedLoggerProxy =
13
+ if defined?(::ActionCable::Server::TaggedLoggerProxy)
14
+ ::ActionCable::Server::TaggedLoggerProxy
15
+ else
16
+ require "action_cable/connection/tagged_logger_proxy"
17
+ ::ActionCable::Connection::TaggedLoggerProxy
24
18
  end
19
+ end
20
+ end
25
21
 
26
- # Upstream defines the severity methods with a single-arg signature
27
- # (`message = nil`), which discards Semantic Logger's richer payload and
28
- # exception arguments and raises ArgumentError when they are supplied.
29
- # Redefine them to forward the full Semantic Logger signature down to the
30
- # wrapped logger, while still applying the connection's tags. See #220.
31
- %i[debug info warn error fatal unknown].each do |severity|
32
- define_method(severity) do |message = nil, payload = nil, exception = nil, &block|
33
- tag(@logger) { forward(severity, message, payload, exception, &block) }
34
- end
35
- end
22
+ RailsSemanticLogger::ActionCable::TaggedLoggerProxy.class_eval do
23
+ # Mirrors upstream #tag, including the `respond_to?(:tagged)` guard so a
24
+ # target logger without tagging support (e.g. when handed a non-tagged
25
+ # ActiveRecord::Base.logger by the worker pool) simply yields. Diverges in
26
+ # one place: upstream reads the already-applied tags via
27
+ # `logger.formatter.current_tags` (ActiveSupport::TaggedLogging), but
28
+ # Semantic Logger exposes them via `#tags`, so resolve from whichever the
29
+ # target logger supports. See #220.
30
+ def tag(logger, &)
31
+ if logger.respond_to?(:tagged)
32
+ current_tags = tags - applied_tags_for(logger)
33
+ logger.tagged(*current_tags, &)
34
+ else
35
+ yield
36
+ end
37
+ end
36
38
 
37
- private
39
+ # Upstream defines the severity methods with a single-arg signature
40
+ # (`message = nil`), which discards Semantic Logger's richer payload and
41
+ # exception arguments and raises ArgumentError when they are supplied.
42
+ # Redefine them to forward the full Semantic Logger signature down to the
43
+ # wrapped logger, while still applying the connection's tags. See #220.
44
+ %i[debug info warn error fatal unknown].each do |severity|
45
+ define_method(severity) do |message = nil, payload = nil, exception = nil, &block|
46
+ tag(@logger) { forward(severity, message, payload, exception, &block) }
47
+ end
48
+ end
38
49
 
39
- # Only forward the extra payload/exception arguments when the wrapped logger's
40
- # method can accept them. A standard Ruby Logger (e.g. the one wrapped by
41
- # ActionCable::Connection::TestCase) only accepts a single `progname` argument
42
- # and raises ArgumentError given more, so fall back to the single-arg call. See #317.
43
- def forward(severity, message, payload, exception, &)
44
- if extended_signature?(@logger, severity)
45
- @logger.public_send(severity, message, payload, exception, &)
46
- else
47
- @logger.public_send(severity, message, &)
48
- end
49
- end
50
+ private
50
51
 
51
- def extended_signature?(logger, severity)
52
- params = logger.method(severity).parameters
53
- params.any? { |type, _| type == :rest } || params.count { |type, _| %i[req opt].include?(type) } >= 3
54
- end
52
+ # Only forward the extra payload/exception arguments when the wrapped logger's
53
+ # method can accept them. A standard Ruby Logger (e.g. the one wrapped by
54
+ # ActionCable::Connection::TestCase) only accepts a single `progname` argument
55
+ # and raises ArgumentError given more, so fall back to the single-arg call. See #317.
56
+ def forward(severity, message, payload, exception, &)
57
+ if extended_signature?(@logger, severity)
58
+ @logger.public_send(severity, message, payload, exception, &)
59
+ else
60
+ @logger.public_send(severity, message, &)
61
+ end
62
+ end
55
63
 
56
- # Tags already applied to the target logger, so they are not duplicated.
57
- # Semantic Logger exposes them via `#tags`; ActiveSupport::TaggedLogging
58
- # via `formatter.current_tags`. Fall back to none when neither is present.
59
- def applied_tags_for(logger)
60
- if logger.respond_to?(:tags)
61
- Array(logger.tags)
62
- elsif logger.respond_to?(:formatter) && logger.formatter.respond_to?(:current_tags)
63
- logger.formatter.current_tags
64
- else
65
- []
66
- end
67
- end
64
+ def extended_signature?(logger, severity)
65
+ params = logger.method(severity).parameters
66
+ params.any? { |type, _| type == :rest } || params.count { |type, _| %i[req opt].include?(type) } >= 3
67
+ end
68
+
69
+ # Tags already applied to the target logger, so they are not duplicated.
70
+ # Semantic Logger exposes them via `#tags`; ActiveSupport::TaggedLogging
71
+ # via `formatter.current_tags`. Fall back to none when neither is present.
72
+ def applied_tags_for(logger)
73
+ if logger.respond_to?(:tags)
74
+ Array(logger.tags)
75
+ elsif logger.respond_to?(:formatter) && logger.formatter.respond_to?(:current_tags)
76
+ logger.formatter.current_tags
77
+ else
78
+ []
68
79
  end
69
80
  end
70
81
  end
@@ -256,14 +256,56 @@ module RailsSemanticLogger
256
256
  @add_file_appender = value
257
257
  end
258
258
 
259
+ # Emit the deprecation warnings recorded by the deprecated appender option
260
+ # setters, and warn immediately from any later call. Called by the engine once
261
+ # Rails has applied the application's deprecation configuration.
262
+ #
263
+ # The deprecated options are documented to be set in `config/application.rb` or
264
+ # `config/environments/*.rb`, which Rails reads in `load_environment_config`,
265
+ # long before `active_support.deprecation_behavior` applies
266
+ # `config.active_support.report_deprecations`, `config.active_support.deprecation`,
267
+ # and any per-deprecator settings. Warning from the setter itself would therefore
268
+ # land in a window where nothing the application configures can reach it. The
269
+ # setters record instead, and this flushes once the settings are in place.
270
+ #
271
+ # Each option is reported once, attributed to the first place it was set, so an
272
+ # application setting several deprecated options gets one warning per option
273
+ # rather than one per assignment.
274
+ def flush_deprecations!
275
+ @deprecations_flushed = true
276
+ pending = pending_deprecations
277
+ @pending_deprecations = {}
278
+ pending.each_value { |message, callstack| RailsSemanticLogger.deprecator.warn(message, callstack) }
279
+ nil
280
+ end
281
+
259
282
  private
260
283
 
261
284
  def deprecate_appender_option(option, via: "appenders.add(...)")
262
- RailsSemanticLogger.deprecator.warn(
285
+ message =
263
286
  "`config.rails_semantic_logger.#{option}=` is deprecated and will be removed in a future release. " \
264
287
  "Declare the destination and formatting directly instead, via " \
265
288
  "`config.rails_semantic_logger.appenders { |appenders| #{via} }`."
266
- )
289
+
290
+ # Skip this method and the setter that called it, so the warning is attributed
291
+ # to the application code that set the option, whether it is emitted now or
292
+ # flushed later by #flush_deprecations!.
293
+ callstack = caller_locations(2)
294
+
295
+ return RailsSemanticLogger.deprecator.warn(message, callstack) if deprecations_flushed?
296
+
297
+ pending_deprecations[option] ||= [message, callstack]
298
+ nil
299
+ end
300
+
301
+ # Deprecations recorded before Rails applied its deprecation configuration,
302
+ # keyed by option so that each is reported only once. See #flush_deprecations!.
303
+ def pending_deprecations
304
+ @pending_deprecations ||= {}
305
+ end
306
+
307
+ def deprecations_flushed?
308
+ defined?(@deprecations_flushed) && @deprecations_flushed
267
309
  end
268
310
 
269
311
  # Warn when an init-time setting is changed after the logger and its
@@ -1,3 +1,3 @@
1
1
  module RailsSemanticLogger
2
- VERSION = "5.1.0".freeze
2
+ VERSION = "5.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
@@ -83,13 +83,13 @@ files:
83
83
  - lib/rails_semantic_logger/sidekiq/loggable.rb
84
84
  - lib/rails_semantic_logger/solid_queue/log_subscriber.rb
85
85
  - lib/rails_semantic_logger/version.rb
86
- homepage: https://logger.rocketjob.io
86
+ homepage: https://logger.reidmorrison.com
87
87
  licenses:
88
88
  - Apache-2.0
89
89
  metadata:
90
90
  bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
91
- documentation_uri: https://logger.rocketjob.io
92
- source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v5.1.0
91
+ documentation_uri: https://logger.reidmorrison.com
92
+ source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v5.2.0
93
93
  changelog_uri: https://github.com/reidmorrison/rails_semantic_logger/blob/main/CHANGELOG.md
94
94
  rubygems_mfa_required: 'true'
95
95
  rdoc_options: []