rails_semantic_logger 4.12.0 → 4.13.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: 73a37ac27f2cf94d083cc75aa557a778f32e2de852b3be6447b072dc1da89047
4
- data.tar.gz: 681f2145e71def6b336792fe3d581dfd89da6fd3ca471befcbd8ffa4f11abb50
3
+ metadata.gz: b82f4b18da96047400658caaf0cbdb073ac21d0d9dfc9f8e89a270fae80550af
4
+ data.tar.gz: fcef56ce1f917619d302b3dced8680748f0945c3a5a16763aadf21007ef1a00d
5
5
  SHA512:
6
- metadata.gz: 8d299a14cb4c3eaf282e4bf502d8e60c2a36095b138c17969cf0a8f79b0431a731adbe8963ae2017bf429f12b7f42fe65d5c199a2c5f88e984a71d4605766bea
7
- data.tar.gz: d837dc46c0dcd38b19dcf2a62c926c91ef1775542d55c8919d3a76db2e62764ab8675890238da78ab19b157f3b920e9d92257d5b2e347bb66d0c5a2bde60441f
6
+ metadata.gz: 6ca5b2a92ca494065abb52d7d44eb71e06ba044f190c10b710549b609f78924542eb4f5eb126c54f98bc1248daaa7e1e29b35139c527081f178c1119be76acdc
7
+ data.tar.gz: 604c669579b6bf2e25b718008406fd2a5bfcacd32f39a5714b05656773e59634d15d10d3afd0277c098bc73f5836e577ad1412669947598b206f22e5af4379d4
@@ -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
 
@@ -127,7 +127,7 @@ module RailsSemanticLogger
127
127
  end
128
128
 
129
129
  # Replace the Bugsnag logger
130
- Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
130
+ Bugsnag.configure(false) { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
131
131
 
132
132
  # Set the IOStreams PGP logger
133
133
  IOStreams::Pgp.logger = SemanticLogger["IOStreams::Pgp"] if defined?(IOStreams)
@@ -138,7 +138,7 @@ module RailsSemanticLogger
138
138
  config = Rails.application.config
139
139
 
140
140
  # Replace the Bugsnag logger
141
- 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)
142
142
 
143
143
  # Rails Patches
144
144
  require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(::ActionCable)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsSemanticLogger
2
- VERSION = "4.12.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.12.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: 2023-03-27 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
@@ -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
@@ -89,7 +90,7 @@ licenses:
89
90
  metadata:
90
91
  bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
91
92
  documentation_uri: https://logger.rocketjob.io
92
- source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/4.12.0
93
+ source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.13.0
93
94
  rubygems_mfa_required: 'true'
94
95
  post_install_message:
95
96
  rdoc_options: []