rails_semantic_logger 4.11.0 → 4.13.0

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: 6944c99a390bc385a4d5a83daea0fc340dbd4dd2913631ae3a812590ec1503e4
4
- data.tar.gz: ebb36106bde192de58b716077fc4c1b5c51d474ee9e86e5a93ef4a77fc25d1be
3
+ metadata.gz: b82f4b18da96047400658caaf0cbdb073ac21d0d9dfc9f8e89a270fae80550af
4
+ data.tar.gz: fcef56ce1f917619d302b3dced8680748f0945c3a5a16763aadf21007ef1a00d
5
5
  SHA512:
6
- metadata.gz: 1e1cf6df574f6dd146029407d80d2a4b51e1bfb222dbf511dbc6b540070e8d7432cff0eaf4cf94227b2d5440eb21c2ebab7222db774dd9408ebda613ae0df3bf
7
- data.tar.gz: 2da852f09a5417bc91e155f1bb80d9a1c50baa823cd39c46ee2ea7a9ecfa366f95b551c996a3a295d6074424224fd5aaf390c14c7f08b88effdcae31486d3bc4
6
+ metadata.gz: 6ca5b2a92ca494065abb52d7d44eb71e06ba044f190c10b710549b609f78924542eb4f5eb126c54f98bc1248daaa7e1e29b35139c527081f178c1119be76acdc
7
+ data.tar.gz: 604c669579b6bf2e25b718008406fd2a5bfcacd32f39a5714b05656773e59634d15d10d3afd0277c098bc73f5836e577ad1412669947598b206f22e5af4379d4
@@ -14,12 +14,22 @@ module RailsSemanticLogger
14
14
 
15
15
  # Unused, but needed for Devise 401 status code monkey patch to still work.
16
16
  ::ActionController::Base.log_process_action(payload)
17
+
18
+ params = payload[:params]
17
19
 
18
- # According to PR https://github.com/reidmorrison/rails_semantic_logger/pull/37/files
19
- # payload[:params] is not always a Hash.
20
- payload[:params] = payload[:params].to_unsafe_h unless payload[:params].is_a?(Hash)
21
- payload[:params] = payload[:params].except(*INTERNAL_PARAMS)
22
- payload.delete(:params) if payload[:params].empty?
20
+ if params.kind_of?(Hash) || params.kind_of?(::ActionController::Parameters)
21
+ # According to PR https://github.com/reidmorrison/rails_semantic_logger/pull/37/files
22
+ # params is not always a Hash.
23
+ payload[:params] = params.to_unsafe_h unless params.is_a?(Hash)
24
+ payload[:params] = params.except(*INTERNAL_PARAMS)
25
+
26
+ if payload[:params].empty?
27
+ payload.delete(:params)
28
+ elsif params["file"]
29
+ # When logging to JSON the entire tempfile is logged, so convert it to a string.
30
+ payload[:params]["file"] = params["file"].inspect
31
+ end
32
+ end
23
33
 
24
34
  format = payload[:format]
25
35
  payload[:format] = format.to_s.upcase if format.is_a?(Symbol)
@@ -48,12 +58,6 @@ module RailsSemanticLogger
48
58
  payload.delete(:request)
49
59
  payload.delete(:response)
50
60
 
51
- params = payload[:params]
52
- if params
53
- # When logging to JSON the entire tempfile is logged, so convert it to a string.
54
- params["file"] = params["file"].inspect if params["file"]
55
- end
56
-
57
61
  {
58
62
  message: "Completed ##{payload[:action]}",
59
63
  duration: event.duration,
@@ -9,7 +9,7 @@ module RailsSemanticLogger
9
9
  message_id = event.payload[:message_id]
10
10
  duration = event.duration.round(1)
11
11
  if ex
12
- log_with_formatter event: event, log_duration: true, level: :error do |fmt|
12
+ log_with_formatter event: event, log_duration: true, level: :error do |fmt|
13
13
  {
14
14
  message: "Error delivering mail #{message_id} (#{duration}ms)",
15
15
  exception: ex
@@ -17,7 +17,7 @@ module RailsSemanticLogger
17
17
  end
18
18
  else
19
19
  message = begin
20
- if event.payload[:perform_deliveries]
20
+ if event.payload[:perform_deliveries]
21
21
  "Delivered mail #{message_id} (#{duration}ms)"
22
22
  else
23
23
  "Skipped delivery of mail #{message_id} as `perform_deliveries` is false"
@@ -92,7 +92,7 @@ module RailsSemanticLogger
92
92
  end
93
93
 
94
94
  def formatted_args
95
- if defined?(mailer.contantize.log_arguments?) && !mailer.contantize.log_arguments?
95
+ if defined?(mailer.constantize.log_arguments?) && !mailer.constantize.log_arguments?
96
96
  ""
97
97
  else
98
98
  JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) }) if event.payload[:args].present?
@@ -19,10 +19,10 @@ module RailsSemanticLogger
19
19
  def render_template(event)
20
20
  return unless should_log?
21
21
 
22
- payload = {
22
+ payload = {
23
23
  template: from_rails_root(event.payload[:identifier])
24
24
  }
25
- payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
25
+ payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
26
26
  payload[:allocations] = event.allocations if event.respond_to?(:allocations)
27
27
 
28
28
  logger.measure(
@@ -36,11 +36,11 @@ module RailsSemanticLogger
36
36
  def render_partial(event)
37
37
  return unless should_log?
38
38
 
39
- payload = {
39
+ payload = {
40
40
  partial: from_rails_root(event.payload[:identifier])
41
41
  }
42
- payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
43
- payload[:cache] = event.payload[:cache_hit] unless event.payload[:cache_hit].nil?
42
+ payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
43
+ payload[:cache] = event.payload[:cache_hit] unless event.payload[:cache_hit].nil?
44
44
  payload[:allocations] = event.allocations if event.respond_to?(:allocations)
45
45
 
46
46
  logger.measure(
@@ -56,11 +56,11 @@ module RailsSemanticLogger
56
56
 
57
57
  identifier = event.payload[:identifier] || "templates"
58
58
 
59
- payload = {
59
+ payload = {
60
60
  template: from_rails_root(identifier),
61
61
  count: event.payload[:count]
62
62
  }
63
- payload[:cache_hits] = event.payload[:cache_hits] if event.payload[:cache_hits]
63
+ payload[:cache_hits] = event.payload[:cache_hits] if event.payload[:cache_hits]
64
64
  payload[:allocations] = event.allocations if event.respond_to?(:allocations)
65
65
 
66
66
  logger.measure(
@@ -72,16 +72,58 @@ module RailsSemanticLogger
72
72
  end
73
73
 
74
74
  def start(name, id, payload)
75
- if (name == "render_template.action_view") && should_log?
76
- payload = {template: from_rails_root(payload[:identifier])}
75
+ if (name == "render_template.action_view" || name == "render_layout.action_view") && should_log?
76
+ qualifier = " layout" if name == "render_layout.action_view"
77
+ payload = { template: from_rails_root(payload[:identifier]) }
77
78
  payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
78
79
 
79
- logger.send(self.class.rendered_log_level, message: "Rendering", payload: payload)
80
+ logger.send(self.class.rendered_log_level, message: "Rendering#{qualifier}", payload: payload)
80
81
  end
81
82
 
82
83
  super
83
84
  end
84
85
 
86
+ if (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
87
+ class Start # :nodoc:
88
+ def start(name, id, payload)
89
+ return unless %w[render_template.action_view render_layout.action_view].include?(name)
90
+
91
+ qualifier = " layout" if name == "render_layout.action_view"
92
+ payload = { template: from_rails_root(payload[:identifier]) }
93
+ payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
94
+
95
+ logger.debug(message: "Rendering#{qualifier}", payload: payload)
96
+ end
97
+
98
+ def finish(name, id, payload) end
99
+
100
+ private
101
+
102
+ def from_rails_root(string)
103
+ string = string.sub(rails_root, "")
104
+ string.sub!(VIEWS_PATTERN, "")
105
+ string
106
+ end
107
+
108
+ def rails_root # :doc:
109
+ @root ||= "#{Rails.root}/"
110
+ end
111
+
112
+ def logger
113
+ @logger ||= SemanticLogger["ActionView"]
114
+ end
115
+ end
116
+
117
+ def self.attach_to(*)
118
+ ActiveSupport::Notifications.unsubscribe("render_template.action_view")
119
+ ActiveSupport::Notifications.unsubscribe("render_layout.action_view")
120
+ ActiveSupport::Notifications.subscribe("render_template.action_view", RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
121
+ ActiveSupport::Notifications.subscribe("render_layout.action_view", RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
122
+
123
+ super
124
+ end
125
+ end
126
+
85
127
  private
86
128
 
87
129
  @logger = SemanticLogger["ActionView"]
@@ -4,14 +4,44 @@ module RailsSemanticLogger
4
4
  module ActiveJob
5
5
  class LogSubscriber < ::ActiveSupport::LogSubscriber
6
6
  def enqueue(event)
7
- log_with_formatter event: event do |fmt|
8
- {message: "Enqueued #{fmt.job_info}"}
7
+ ex = event.payload[:exception_object]
8
+
9
+ if ex
10
+ log_with_formatter level: :error, event: event do |fmt|
11
+ {
12
+ message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
13
+ exception: ex
14
+ }
15
+ end
16
+ elsif event.payload[:aborted]
17
+ log_with_formatter level: :info, event: event do |fmt|
18
+ { message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution." }
19
+ end
20
+ else
21
+ log_with_formatter event: event do |fmt|
22
+ { message: "Enqueued #{fmt.job_info}" }
23
+ end
9
24
  end
10
25
  end
11
26
 
12
27
  def enqueue_at(event)
13
- log_with_formatter event: event do |fmt|
14
- {message: "Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"}
28
+ ex = event.payload[:exception_object]
29
+
30
+ if ex
31
+ log_with_formatter level: :error, event: event do |fmt|
32
+ {
33
+ message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
34
+ exception: ex
35
+ }
36
+ end
37
+ elsif event.payload[:aborted]
38
+ log_with_formatter level: :info, event: event do |fmt|
39
+ { message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution." }
40
+ end
41
+ else
42
+ log_with_formatter event: event do |fmt|
43
+ {message: "Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"}
44
+ end
15
45
  end
16
46
  end
17
47
 
@@ -1,7 +1,4 @@
1
1
  require "rails"
2
- require "action_controller/log_subscriber"
3
- require "action_view/log_subscriber"
4
- require "action_mailer/log_subscriber"
5
2
  require "rails_semantic_logger/options"
6
3
 
7
4
  module RailsSemanticLogger
@@ -111,7 +108,14 @@ module RailsSemanticLogger
111
108
  Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger=)
112
109
 
113
110
  # Replace the Sidekiq logger
114
- Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq) && Sidekiq.respond_to?(:logger=)
111
+ if defined?(Sidekiq)
112
+ if Sidekiq.respond_to?(:logger=)
113
+ Sidekiq.logger = SemanticLogger[Sidekiq]
114
+ elsif Sidekiq::VERSION[0..1] == '7.'
115
+ method = Sidekiq.server? ? :configure_server : :configure_client
116
+ Sidekiq.public_send(method) { |cfg| cfg.logger = SemanticLogger[Sidekiq] }
117
+ end
118
+ end
115
119
 
116
120
  # Replace the Sidetiq logger
117
121
  Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq) && Sidetiq.respond_to?(:logger=)
@@ -123,7 +127,7 @@ module RailsSemanticLogger
123
127
  end
124
128
 
125
129
  # Replace the Bugsnag logger
126
- Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
130
+ Bugsnag.configure(false) { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
127
131
 
128
132
  # Set the IOStreams PGP logger
129
133
  IOStreams::Pgp.logger = SemanticLogger["IOStreams::Pgp"] if defined?(IOStreams)
@@ -134,7 +138,7 @@ module RailsSemanticLogger
134
138
  config = Rails.application.config
135
139
 
136
140
  # Replace the Bugsnag logger
137
- Bugsnag.configure { |bugsnag_config| bugsnag_config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
141
+ Bugsnag.configure(false) { |bugsnag_config| bugsnag_config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
138
142
 
139
143
  # Rails Patches
140
144
  require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(::ActionCable)
@@ -186,26 +190,38 @@ module RailsSemanticLogger
186
190
  end
187
191
 
188
192
  # Action View
189
- RailsSemanticLogger::ActionView::LogSubscriber.rendered_log_level = :info if config.rails_semantic_logger.rendered
190
- RailsSemanticLogger.swap_subscriber(
191
- ::ActionView::LogSubscriber,
192
- RailsSemanticLogger::ActionView::LogSubscriber,
193
- :action_view
194
- )
193
+ if defined?(::ActionView)
194
+ require "action_view/log_subscriber"
195
+
196
+ RailsSemanticLogger::ActionView::LogSubscriber.rendered_log_level = :info if config.rails_semantic_logger.rendered
197
+ RailsSemanticLogger.swap_subscriber(
198
+ ::ActionView::LogSubscriber,
199
+ RailsSemanticLogger::ActionView::LogSubscriber,
200
+ :action_view
201
+ )
202
+ end
195
203
 
196
204
  # Action Controller
197
- RailsSemanticLogger.swap_subscriber(
198
- ::ActionController::LogSubscriber,
199
- RailsSemanticLogger::ActionController::LogSubscriber,
200
- :action_controller
201
- )
205
+ if defined?(::ActionController)
206
+ require "action_controller/log_subscriber"
207
+
208
+ RailsSemanticLogger.swap_subscriber(
209
+ ::ActionController::LogSubscriber,
210
+ RailsSemanticLogger::ActionController::LogSubscriber,
211
+ :action_controller
212
+ )
213
+ end
202
214
 
203
215
  # Action Mailer
204
- RailsSemanticLogger.swap_subscriber(
205
- ::ActionMailer::LogSubscriber,
206
- RailsSemanticLogger::ActionMailer::LogSubscriber,
207
- :action_mailer
208
- )
216
+ if defined?(::ActionMailer)
217
+ require "action_mailer/log_subscriber"
218
+
219
+ RailsSemanticLogger.swap_subscriber(
220
+ ::ActionMailer::LogSubscriber,
221
+ RailsSemanticLogger::ActionMailer::LogSubscriber,
222
+ :action_mailer
223
+ )
224
+ end
209
225
  end
210
226
 
211
227
  #
@@ -9,7 +9,11 @@ module ActiveJob
9
9
 
10
10
  undef_method :tag_logger
11
11
  def tag_logger(*tags, &block)
12
- logger.tagged(*tags, &block)
12
+ if logger.respond_to?(:tagged)
13
+ logger.tagged(*tags, &block)
14
+ else
15
+ yield
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -0,0 +1,11 @@
1
+ require "active_support/log_subscriber"
2
+
3
+ module ActiveSupport
4
+ class LogSubscriber
5
+ # @override Rails 7.1
6
+ def silenced?(event)
7
+ native_log_level = @event_levels.fetch(event, ::Logger::Severity::FATAL)
8
+ logger.nil? || SemanticLogger::Levels.index(logger.level) > SemanticLogger::Levels.index(native_log_level)
9
+ end
10
+ end
11
+ end
@@ -4,7 +4,15 @@ module ActiveSupport
4
4
  # More hacks to try and stop Rails from being it's own worst enemy.
5
5
  class Logger
6
6
  class << self
7
- undef :logger_outputs_to?, :broadcast
7
+ undef :logger_outputs_to?
8
+
9
+ # Prevent broadcasting since SemanticLogger already supports multiple loggers
10
+ if method_defined?(:broadcast)
11
+ undef :broadcast
12
+ def broadcast(logger)
13
+ Module.new
14
+ end
15
+ end
8
16
  end
9
17
 
10
18
  # Prevent Console from trying to merge loggers
@@ -12,11 +20,6 @@ module ActiveSupport
12
20
  true
13
21
  end
14
22
 
15
- # Prevent broadcasting since SemanticLogger already supports multiple loggers
16
- def self.broadcast(logger)
17
- Module.new
18
- end
19
-
20
23
  def self.new(*args, **kwargs)
21
24
  SemanticLogger[self]
22
25
  end
@@ -35,16 +35,18 @@ module RailsSemanticLogger
35
35
  @started_request_log_level = :debug
36
36
 
37
37
  def call_app(request, env)
38
- instrumenter = ActiveSupport::Notifications.instrumenter
39
- instrumenter.start "request.action_dispatch", request: request
38
+ instrumenter = ActiveSupport::Notifications.instrumenter
39
+ instrumenter_state = instrumenter.start "request.action_dispatch", request: request
40
+ instrumenter_finish = -> () {
41
+ instrumenter.finish_with_state(instrumenter_state, "request.action_dispatch", request: request)
42
+ }
40
43
 
41
44
  logger.send(self.class.started_request_log_level) { started_request_message(request) }
42
-
43
45
  status, headers, body = @app.call(env)
44
- body = ::Rack::BodyProxy.new(body) { finish(request) }
46
+ body = ::Rack::BodyProxy.new(body, &instrumenter_finish)
45
47
  [status, headers, body]
46
48
  rescue Exception
47
- finish(request)
49
+ instrumenter_finish.call
48
50
  raise
49
51
  end
50
52
 
@@ -90,11 +92,6 @@ module RailsSemanticLogger
90
92
  tagged
91
93
  end
92
94
 
93
- def finish(request)
94
- instrumenter = ActiveSupport::Notifications.instrumenter
95
- instrumenter.finish "request.action_dispatch", request: request
96
- end
97
-
98
95
  def logger
99
96
  self.class.logger
100
97
  end
@@ -1,3 +1,3 @@
1
1
  module RailsSemanticLogger
2
- VERSION = "4.11.0".freeze
2
+ VERSION = "4.13.0".freeze
3
3
  end
@@ -58,4 +58,5 @@ end
58
58
 
59
59
  require("rails_semantic_logger/extensions/mongoid/config") if defined?(Mongoid)
60
60
  require("rails_semantic_logger/extensions/active_support/logger") if defined?(ActiveSupport::Logger)
61
+ require("rails_semantic_logger/extensions/active_support/log_subscriber") if defined?(ActiveSupport::LogSubscriber)
61
62
  require("rails_semantic_logger/extensions/rack/server") if defined?(Rack::Server)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.0
4
+ version: 4.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-10 00:00:00.000000000 Z
11
+ date: 2023-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '4.9'
47
+ version: '4.13'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '4.9'
54
+ version: '4.13'
55
55
  description:
56
56
  email:
57
57
  executables: []
@@ -75,6 +75,7 @@ files:
75
75
  - lib/rails_semantic_logger/extensions/action_view/streaming_template_renderer.rb
76
76
  - lib/rails_semantic_logger/extensions/active_job/logging.rb
77
77
  - lib/rails_semantic_logger/extensions/active_model_serializers/logging.rb
78
+ - lib/rails_semantic_logger/extensions/active_support/log_subscriber.rb
78
79
  - lib/rails_semantic_logger/extensions/active_support/logger.rb
79
80
  - lib/rails_semantic_logger/extensions/active_support/tagged_logging.rb
80
81
  - lib/rails_semantic_logger/extensions/mongoid/config.rb
@@ -86,7 +87,11 @@ files:
86
87
  homepage: https://logger.rocketjob.io
87
88
  licenses:
88
89
  - Apache-2.0
89
- metadata: {}
90
+ metadata:
91
+ bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
92
+ documentation_uri: https://logger.rocketjob.io
93
+ source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.13.0
94
+ rubygems_mfa_required: 'true'
90
95
  post_install_message:
91
96
  rdoc_options: []
92
97
  require_paths:
@@ -102,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
107
  - !ruby/object:Gem::Version
103
108
  version: '0'
104
109
  requirements: []
105
- rubygems_version: 3.1.6
110
+ rubygems_version: 3.4.9
106
111
  signing_key:
107
112
  specification_version: 4
108
113
  summary: Feature rich logging framework that replaces the Rails logger.