rails_semantic_logger 4.13.0 → 4.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_semantic_logger/action_controller/log_subscriber.rb +5 -3
- data/lib/rails_semantic_logger/action_mailer/log_subscriber.rb +10 -12
- data/lib/rails_semantic_logger/action_view/log_subscriber.rb +15 -12
- data/lib/rails_semantic_logger/active_job/log_subscriber.rb +6 -6
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +1 -3
- data/lib/rails_semantic_logger/engine.rb +9 -5
- data/lib/rails_semantic_logger/extensions/action_dispatch/debug_exceptions.rb +11 -3
- data/lib/rails_semantic_logger/extensions/active_support/log_subscriber.rb +9 -7
- data/lib/rails_semantic_logger/extensions/active_support/logger.rb +3 -3
- data/lib/rails_semantic_logger/extensions/rackup/server.rb +12 -0
- data/lib/rails_semantic_logger/extensions/rails/server.rb +1 -1
- data/lib/rails_semantic_logger/extensions/sidekiq/sidekiq.rb +211 -0
- data/lib/rails_semantic_logger/rack/logger.rb +1 -1
- data/lib/rails_semantic_logger/version.rb +1 -1
- data/lib/rails_semantic_logger.rb +21 -3
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bb41dd02df0dc0dc472a66f83a82146878942a309670d4fb10da64bfdae4bc4
|
4
|
+
data.tar.gz: c1463e8da359c87fffc4e7d4e56919609320473fa0702b6a7f9b9fec1bdc5050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1604cdbeed7b9bda178517f7cd7f72e4721523cf222aa6b0a2dcce36fc77c62807641ca32aef349f91c9e5aa86d04e9202e15adff71e4b5e4e29798a3c9dde16
|
7
|
+
data.tar.gz: b0e79372c2111bb823c191595a600c8c4c218e6989249f66c0ec46d66826116abfe2f6c5c761d33ae23f1494e7a74b8299d70b037410570757195115b212dced
|
@@ -14,10 +14,10 @@ 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
|
-
|
17
|
+
|
18
18
|
params = payload[:params]
|
19
19
|
|
20
|
-
if params.
|
20
|
+
if params.is_a?(Hash) || params.is_a?(::ActionController::Parameters)
|
21
21
|
# According to PR https://github.com/reidmorrison/rails_semantic_logger/pull/37/files
|
22
22
|
# params is not always a Hash.
|
23
23
|
payload[:params] = params.to_unsafe_h unless params.is_a?(Hash)
|
@@ -79,7 +79,9 @@ module RailsSemanticLogger
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def send_data(event)
|
82
|
-
controller_logger(event).info(message:
|
82
|
+
controller_logger(event).info(message: "Sent data",
|
83
|
+
payload: {file_name: event.payload[:filename]},
|
84
|
+
duration: event.duration)
|
83
85
|
end
|
84
86
|
|
85
87
|
def unpermitted_parameters(event)
|
@@ -9,22 +9,22 @@ 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 |
|
12
|
+
log_with_formatter event: event, log_duration: true, level: :error do |_fmt|
|
13
13
|
{
|
14
|
-
message:
|
14
|
+
message: "Error delivering mail #{message_id} (#{duration}ms)",
|
15
15
|
exception: ex
|
16
16
|
}
|
17
17
|
end
|
18
18
|
else
|
19
|
-
message =
|
19
|
+
message =
|
20
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"
|
24
24
|
end
|
25
|
-
|
26
|
-
log_with_formatter event: event, log_duration: true do |
|
27
|
-
{
|
25
|
+
|
26
|
+
log_with_formatter event: event, log_duration: true do |_fmt|
|
27
|
+
{message: message}
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -34,8 +34,8 @@ module RailsSemanticLogger
|
|
34
34
|
mailer = event.payload[:mailer]
|
35
35
|
action = event.payload[:action]
|
36
36
|
duration = event.duration.round(1)
|
37
|
-
log_with_formatter event: event do |
|
38
|
-
{
|
37
|
+
log_with_formatter event: event do |_fmt|
|
38
|
+
{message: "#{mailer}##{action}: processed outbound mail in #{duration}ms"}
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -74,8 +74,6 @@ module RailsSemanticLogger
|
|
74
74
|
event.payload[:date].to_time.utc
|
75
75
|
elsif event.payload[:date].is_a?(String)
|
76
76
|
Time.parse(date).utc
|
77
|
-
else
|
78
|
-
nil
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
@@ -94,8 +92,8 @@ module RailsSemanticLogger
|
|
94
92
|
def formatted_args
|
95
93
|
if defined?(mailer.constantize.log_arguments?) && !mailer.constantize.log_arguments?
|
96
94
|
""
|
97
|
-
|
98
|
-
JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) })
|
95
|
+
elsif event.payload[:args].present?
|
96
|
+
JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) })
|
99
97
|
end
|
100
98
|
end
|
101
99
|
|
@@ -19,7 +19,7 @@ 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
25
|
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
|
@@ -36,7 +36,7 @@ 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
42
|
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
|
@@ -56,7 +56,7 @@ 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
|
}
|
@@ -72,9 +72,9 @@ module RailsSemanticLogger
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def start(name, id, payload)
|
75
|
-
if
|
75
|
+
if ["render_template.action_view", "render_layout.action_view"].include?(name) && should_log?
|
76
76
|
qualifier = " layout" if name == "render_layout.action_view"
|
77
|
-
payload = {
|
77
|
+
payload = {template: from_rails_root(payload[:identifier])}
|
78
78
|
payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
|
79
79
|
|
80
80
|
logger.send(self.class.rendered_log_level, message: "Rendering#{qualifier}", payload: payload)
|
@@ -84,18 +84,19 @@ module RailsSemanticLogger
|
|
84
84
|
end
|
85
85
|
|
86
86
|
if (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
|
87
|
-
class Start
|
88
|
-
def start(name,
|
87
|
+
class Start
|
88
|
+
def start(name, _id, payload)
|
89
89
|
return unless %w[render_template.action_view render_layout.action_view].include?(name)
|
90
90
|
|
91
91
|
qualifier = " layout" if name == "render_layout.action_view"
|
92
|
-
payload = {
|
92
|
+
payload = {template: from_rails_root(payload[:identifier])}
|
93
93
|
payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
|
94
94
|
|
95
95
|
logger.debug(message: "Rendering#{qualifier}", payload: payload)
|
96
96
|
end
|
97
97
|
|
98
|
-
def finish(name, id, payload)
|
98
|
+
def finish(name, id, payload)
|
99
|
+
end
|
99
100
|
|
100
101
|
private
|
101
102
|
|
@@ -105,7 +106,7 @@ module RailsSemanticLogger
|
|
105
106
|
string
|
106
107
|
end
|
107
108
|
|
108
|
-
def rails_root
|
109
|
+
def rails_root
|
109
110
|
@root ||= "#{Rails.root}/"
|
110
111
|
end
|
111
112
|
|
@@ -117,8 +118,10 @@ module RailsSemanticLogger
|
|
117
118
|
def self.attach_to(*)
|
118
119
|
ActiveSupport::Notifications.unsubscribe("render_template.action_view")
|
119
120
|
ActiveSupport::Notifications.unsubscribe("render_layout.action_view")
|
120
|
-
ActiveSupport::Notifications.subscribe("render_template.action_view",
|
121
|
-
|
121
|
+
ActiveSupport::Notifications.subscribe("render_template.action_view",
|
122
|
+
RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
|
123
|
+
ActiveSupport::Notifications.subscribe("render_layout.action_view",
|
124
|
+
RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
|
122
125
|
|
123
126
|
super
|
124
127
|
end
|
@@ -9,17 +9,17 @@ module RailsSemanticLogger
|
|
9
9
|
if ex
|
10
10
|
log_with_formatter level: :error, event: event do |fmt|
|
11
11
|
{
|
12
|
-
message:
|
12
|
+
message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
|
13
13
|
exception: ex
|
14
14
|
}
|
15
15
|
end
|
16
16
|
elsif event.payload[:aborted]
|
17
17
|
log_with_formatter level: :info, event: event do |fmt|
|
18
|
-
{
|
18
|
+
{message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."}
|
19
19
|
end
|
20
20
|
else
|
21
21
|
log_with_formatter event: event do |fmt|
|
22
|
-
{
|
22
|
+
{message: "Enqueued #{fmt.job_info}"}
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -30,13 +30,13 @@ module RailsSemanticLogger
|
|
30
30
|
if ex
|
31
31
|
log_with_formatter level: :error, event: event do |fmt|
|
32
32
|
{
|
33
|
-
message:
|
33
|
+
message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
|
34
34
|
exception: ex
|
35
35
|
}
|
36
36
|
end
|
37
37
|
elsif event.payload[:aborted]
|
38
38
|
log_with_formatter level: :info, event: event do |fmt|
|
39
|
-
{
|
39
|
+
{message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."}
|
40
40
|
end
|
41
41
|
else
|
42
42
|
log_with_formatter event: event do |fmt|
|
@@ -56,7 +56,7 @@ module RailsSemanticLogger
|
|
56
56
|
if ex
|
57
57
|
log_with_formatter event: event, log_duration: true, level: :error do |fmt|
|
58
58
|
{
|
59
|
-
message:
|
59
|
+
message: "Error performing #{fmt.job_info} in #{event.duration.round(2)}ms",
|
60
60
|
exception: ex
|
61
61
|
}
|
62
62
|
end
|
@@ -169,9 +169,7 @@ module RailsSemanticLogger
|
|
169
169
|
def render_bind_v6_1(attr, value)
|
170
170
|
case attr
|
171
171
|
when ActiveModel::Attribute
|
172
|
-
if attr.type.binary? && attr.value
|
173
|
-
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
|
174
|
-
end
|
172
|
+
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" if attr.type.binary? && attr.value
|
175
173
|
when Array
|
176
174
|
attr = attr.first
|
177
175
|
else
|
@@ -77,7 +77,7 @@ module RailsSemanticLogger
|
|
77
77
|
logger = SemanticLogger[Rails]
|
78
78
|
logger.warn(
|
79
79
|
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " \
|
80
|
-
|
80
|
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.",
|
81
81
|
e
|
82
82
|
)
|
83
83
|
logger
|
@@ -111,14 +111,14 @@ module RailsSemanticLogger
|
|
111
111
|
if defined?(Sidekiq)
|
112
112
|
if Sidekiq.respond_to?(:logger=)
|
113
113
|
Sidekiq.logger = SemanticLogger[Sidekiq]
|
114
|
-
elsif Sidekiq::VERSION[0..1] ==
|
114
|
+
elsif Sidekiq::VERSION[0..1] == "7."
|
115
115
|
method = Sidekiq.server? ? :configure_server : :configure_client
|
116
116
|
Sidekiq.public_send(method) { |cfg| cfg.logger = SemanticLogger[Sidekiq] }
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
# Replace the Sidetiq logger
|
121
|
-
Sidetiq.logger
|
121
|
+
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq) && Sidetiq.respond_to?(:logger=)
|
122
122
|
|
123
123
|
# Replace the DelayedJob logger
|
124
124
|
if defined?(Delayed::Worker)
|
@@ -143,7 +143,9 @@ module RailsSemanticLogger
|
|
143
143
|
# Rails Patches
|
144
144
|
require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(::ActionCable)
|
145
145
|
require("rails_semantic_logger/extensions/action_controller/live") if defined?(::ActionController::Live)
|
146
|
-
|
146
|
+
if defined?(::ActionDispatch::DebugExceptions)
|
147
|
+
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions")
|
148
|
+
end
|
147
149
|
if defined?(::ActionView::StreamingTemplateRenderer::Body)
|
148
150
|
require("rails_semantic_logger/extensions/action_view/streaming_template_renderer")
|
149
151
|
end
|
@@ -222,6 +224,8 @@ module RailsSemanticLogger
|
|
222
224
|
:action_mailer
|
223
225
|
)
|
224
226
|
end
|
227
|
+
|
228
|
+
require("rails_semantic_logger/extensions/sidekiq/sidekiq") if defined?(::Sidekiq)
|
225
229
|
end
|
226
230
|
|
227
231
|
#
|
@@ -237,7 +241,7 @@ module RailsSemanticLogger
|
|
237
241
|
end
|
238
242
|
|
239
243
|
# Re-open appenders after Resque has forked a worker
|
240
|
-
Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque)
|
244
|
+
Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque.after_fork)
|
241
245
|
|
242
246
|
# Re-open appenders after Spring has forked a process
|
243
247
|
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
@@ -6,9 +6,17 @@ module ActionDispatch
|
|
6
6
|
private
|
7
7
|
|
8
8
|
undef_method :log_error
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
|
10
|
+
def log_error(_request, wrapper)
|
11
|
+
Rails.application.deprecators.silence do
|
12
|
+
ActionController::Base.logger.fatal(wrapper.exception)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
else
|
16
|
+
def log_error(_request, wrapper)
|
17
|
+
ActiveSupport::Deprecation.silence do
|
18
|
+
ActionController::Base.logger.fatal(wrapper.exception)
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
if ActiveSupport::VERSION::STRING == "7.1.1"
|
2
|
+
require "active_support/log_subscriber"
|
2
3
|
|
3
|
-
module ActiveSupport
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module ActiveSupport
|
5
|
+
class LogSubscriber
|
6
|
+
# @override Rails 7.1
|
7
|
+
def silenced?(event)
|
8
|
+
native_log_level = @event_levels.fetch(event, ::Logger::Severity::FATAL)
|
9
|
+
logger.nil? || SemanticLogger::Levels.index(logger.level) > SemanticLogger::Levels.index(native_log_level)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -9,18 +9,18 @@ module ActiveSupport
|
|
9
9
|
# Prevent broadcasting since SemanticLogger already supports multiple loggers
|
10
10
|
if method_defined?(:broadcast)
|
11
11
|
undef :broadcast
|
12
|
-
def broadcast(
|
12
|
+
def broadcast(_logger)
|
13
13
|
Module.new
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
# Prevent Console from trying to merge loggers
|
19
|
-
def self.logger_outputs_to?(*
|
19
|
+
def self.logger_outputs_to?(*_args)
|
20
20
|
true
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.new(*
|
23
|
+
def self.new(*_args, **_kwargs)
|
24
24
|
SemanticLogger[self]
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# Sidekiq patches
|
2
|
+
#
|
3
|
+
# To re-enable stdout logging for sidekiq server processes, add the following snippet to config/initializers/sidekiq.rb:
|
4
|
+
# Sidekiq.configure_server do |config|
|
5
|
+
# SemanticLogger.add_appender(io: $stdout, level: :debug, formatter: :color)
|
6
|
+
# end
|
7
|
+
if Sidekiq::VERSION.to_i == 4
|
8
|
+
require "sidekiq/exception_handler"
|
9
|
+
require "sidekiq/logging"
|
10
|
+
require "sidekiq/middleware/server/logging"
|
11
|
+
require "sidekiq/processor"
|
12
|
+
require "sidekiq/worker"
|
13
|
+
elsif Sidekiq::VERSION.to_i == 5
|
14
|
+
require "sidekiq/exception_handler"
|
15
|
+
require "sidekiq/job_logger"
|
16
|
+
require "sidekiq/logging"
|
17
|
+
require "sidekiq/worker"
|
18
|
+
elsif Sidekiq::VERSION.to_i == 6 && Sidekiq::VERSION.to_f < 6.5
|
19
|
+
require "sidekiq/exception_handler"
|
20
|
+
require "sidekiq/job_logger"
|
21
|
+
require "sidekiq/worker"
|
22
|
+
elsif Sidekiq::VERSION.to_i == 6
|
23
|
+
require "sidekiq/job_logger"
|
24
|
+
require "sidekiq/worker"
|
25
|
+
else
|
26
|
+
require "sidekiq/config"
|
27
|
+
require "sidekiq/job_logger"
|
28
|
+
require "sidekiq/job"
|
29
|
+
end
|
30
|
+
|
31
|
+
module Sidekiq
|
32
|
+
# Sidekiq > v4
|
33
|
+
if defined?(::Sidekiq::JobLogger)
|
34
|
+
# Let Semantic Logger handle duration logging
|
35
|
+
class JobLogger
|
36
|
+
def call(item, queue)
|
37
|
+
klass = item["wrapped"] || item["class"]
|
38
|
+
metric = "Sidekiq/#{klass}/perform" if klass
|
39
|
+
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
40
|
+
logger.info("Start #perform")
|
41
|
+
logger.measure_info(
|
42
|
+
"Completed #perform",
|
43
|
+
on_exception_level: :error,
|
44
|
+
log_exception: :full,
|
45
|
+
metric: metric
|
46
|
+
) do
|
47
|
+
yield
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def prepare(job_hash, &block)
|
52
|
+
level = job_hash["log_level"]
|
53
|
+
if level
|
54
|
+
SemanticLogger.silence(level) do
|
55
|
+
SemanticLogger.tagged(job_hash_context(job_hash), &block)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
SemanticLogger.tagged(job_hash_context(job_hash), &block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def job_hash_context(job_hash)
|
63
|
+
h = {
|
64
|
+
class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"],
|
65
|
+
jid: job_hash["jid"]
|
66
|
+
}
|
67
|
+
h[:bid] = job_hash["bid"] if job_hash["bid"]
|
68
|
+
h[:tags] = job_hash["tags"] if job_hash["tags"]
|
69
|
+
h
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Sidekiq <= v6
|
75
|
+
if defined?(::Sidekiq::Logging)
|
76
|
+
# Replace Sidekiq logging context
|
77
|
+
module Logging
|
78
|
+
def self.with_context(msg, &block)
|
79
|
+
SemanticLogger.tagged(msg, &block)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.job_hash_context(job_hash)
|
83
|
+
klass = job_hash["wrapped"] || job_hash["class"]
|
84
|
+
event = { class: klass, jid: job_hash["jid"] }
|
85
|
+
event[:bid] = job_hash["bid"] if job_hash["bid"]
|
86
|
+
event
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Exception is already logged by Semantic Logger during the perform call
|
92
|
+
# Sidekiq <= v6.5
|
93
|
+
if defined?(::Sidekiq::ExceptionHandler)
|
94
|
+
module ExceptionHandler
|
95
|
+
class Logger
|
96
|
+
def call(ex, ctx)
|
97
|
+
unless ctx.empty?
|
98
|
+
job_hash = ctx[:job] || {}
|
99
|
+
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
|
100
|
+
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
101
|
+
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
# Sidekiq >= v7
|
107
|
+
elsif defined?(::Sidekiq::Config)
|
108
|
+
class Config
|
109
|
+
remove_const :ERROR_HANDLER
|
110
|
+
|
111
|
+
ERROR_HANDLER = ->(ex, ctx, cfg = Sidekiq.default_configuration) {
|
112
|
+
unless ctx.empty?
|
113
|
+
job_hash = ctx[:job] || {}
|
114
|
+
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
|
115
|
+
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
116
|
+
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
|
117
|
+
end
|
118
|
+
}
|
119
|
+
end
|
120
|
+
else
|
121
|
+
# Sidekiq >= 6.5
|
122
|
+
# TODO: Not taking effect. See test/sidekiq_test.rb
|
123
|
+
def self.default_error_handler(ex, ctx)
|
124
|
+
binding.irb
|
125
|
+
unless ctx.empty?
|
126
|
+
job_hash = ctx[:job] || {}
|
127
|
+
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
|
128
|
+
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
129
|
+
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Logging within each worker should use its own logger
|
135
|
+
if Sidekiq::VERSION.to_i == 4
|
136
|
+
module Worker
|
137
|
+
def self.included(base)
|
138
|
+
raise ArgumentError, "You cannot include Sidekiq::Worker in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" }
|
139
|
+
|
140
|
+
base.extend(ClassMethods)
|
141
|
+
base.include(SemanticLogger::Loggable)
|
142
|
+
base.class_attribute :sidekiq_options_hash
|
143
|
+
base.class_attribute :sidekiq_retry_in_block
|
144
|
+
base.class_attribute :sidekiq_retries_exhausted_block
|
145
|
+
end
|
146
|
+
end
|
147
|
+
elsif Sidekiq::VERSION.to_i == 5
|
148
|
+
module Worker
|
149
|
+
def self.included(base)
|
150
|
+
raise ArgumentError, "You cannot include Sidekiq::Worker in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" }
|
151
|
+
|
152
|
+
base.extend(ClassMethods)
|
153
|
+
base.include(SemanticLogger::Loggable)
|
154
|
+
base.sidekiq_class_attribute :sidekiq_options_hash
|
155
|
+
base.sidekiq_class_attribute :sidekiq_retry_in_block
|
156
|
+
base.sidekiq_class_attribute :sidekiq_retries_exhausted_block
|
157
|
+
end
|
158
|
+
end
|
159
|
+
elsif Sidekiq::VERSION.to_i == 6
|
160
|
+
module Worker
|
161
|
+
def self.included(base)
|
162
|
+
raise ArgumentError, "Sidekiq::Worker cannot be included in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" }
|
163
|
+
|
164
|
+
base.include(Options)
|
165
|
+
base.extend(ClassMethods)
|
166
|
+
base.include(SemanticLogger::Loggable)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
else
|
170
|
+
module Job
|
171
|
+
def self.included(base)
|
172
|
+
raise ArgumentError, "Sidekiq::Job cannot be included in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" }
|
173
|
+
|
174
|
+
base.include(Options)
|
175
|
+
base.extend(ClassMethods)
|
176
|
+
base.include(SemanticLogger::Loggable)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
if Sidekiq::VERSION.to_i == 4
|
182
|
+
# Convert string to machine readable format
|
183
|
+
class Processor
|
184
|
+
def log_context(job_hash)
|
185
|
+
klass = job_hash["wrapped"] || job_hash["class"]
|
186
|
+
event = { class: klass, jid: job_hash["jid"] }
|
187
|
+
event[:bid] = job_hash["bid"] if job_hash["bid"]
|
188
|
+
event
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Let Semantic Logger handle duration logging
|
193
|
+
module Middleware
|
194
|
+
module Server
|
195
|
+
class Logging
|
196
|
+
def call(worker, item, queue)
|
197
|
+
worker.logger.info("Start #perform")
|
198
|
+
worker.logger.measure_info(
|
199
|
+
"Completed #perform",
|
200
|
+
on_exception_level: :error,
|
201
|
+
log_exception: :full,
|
202
|
+
metric: "Sidekiq/#{worker.class.name}/perform"
|
203
|
+
) do
|
204
|
+
yield
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -37,7 +37,7 @@ module RailsSemanticLogger
|
|
37
37
|
def call_app(request, env)
|
38
38
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
39
39
|
instrumenter_state = instrumenter.start "request.action_dispatch", request: request
|
40
|
-
instrumenter_finish =
|
40
|
+
instrumenter_finish = lambda {
|
41
41
|
instrumenter.finish_with_state(instrumenter_state, "request.action_dispatch", request: request)
|
42
42
|
}
|
43
43
|
|
@@ -6,21 +6,27 @@ module RailsSemanticLogger
|
|
6
6
|
module ActionController
|
7
7
|
autoload :LogSubscriber, "rails_semantic_logger/action_controller/log_subscriber"
|
8
8
|
end
|
9
|
+
|
9
10
|
module ActionMailer
|
10
11
|
autoload :LogSubscriber, "rails_semantic_logger/action_mailer/log_subscriber"
|
11
12
|
end
|
13
|
+
|
12
14
|
module ActionView
|
13
15
|
autoload :LogSubscriber, "rails_semantic_logger/action_view/log_subscriber"
|
14
16
|
end
|
17
|
+
|
15
18
|
module ActiveJob
|
16
19
|
autoload :LogSubscriber, "rails_semantic_logger/active_job/log_subscriber"
|
17
20
|
end
|
21
|
+
|
18
22
|
module ActiveRecord
|
19
23
|
autoload :LogSubscriber, "rails_semantic_logger/active_record/log_subscriber"
|
20
24
|
end
|
25
|
+
|
21
26
|
module Rack
|
22
27
|
autoload :Logger, "rails_semantic_logger/rack/logger"
|
23
28
|
end
|
29
|
+
|
24
30
|
module DelayedJob
|
25
31
|
autoload :Plugin, "rails_semantic_logger/delayed_job/plugin"
|
26
32
|
end
|
@@ -48,9 +54,11 @@ module RailsSemanticLogger
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def self.subscriber_patterns(subscriber)
|
51
|
-
subscriber.patterns.respond_to?(:keys)
|
52
|
-
subscriber.patterns.keys
|
57
|
+
if subscriber.patterns.respond_to?(:keys)
|
58
|
+
subscriber.patterns.keys
|
59
|
+
else
|
53
60
|
subscriber.patterns
|
61
|
+
end
|
54
62
|
end
|
55
63
|
|
56
64
|
private_class_method :subscriber_patterns, :unattach
|
@@ -59,4 +67,14 @@ end
|
|
59
67
|
require("rails_semantic_logger/extensions/mongoid/config") if defined?(Mongoid)
|
60
68
|
require("rails_semantic_logger/extensions/active_support/logger") if defined?(ActiveSupport::Logger)
|
61
69
|
require("rails_semantic_logger/extensions/active_support/log_subscriber") if defined?(ActiveSupport::LogSubscriber)
|
62
|
-
|
70
|
+
|
71
|
+
begin
|
72
|
+
require 'rackup'
|
73
|
+
rescue LoadError
|
74
|
+
# No need to do anything, will fall back to Rack
|
75
|
+
end
|
76
|
+
if defined?(Rackup::Server)
|
77
|
+
require("rails_semantic_logger/extensions/rackup/server")
|
78
|
+
elsif defined?(Rack::Server)
|
79
|
+
require("rails_semantic_logger/extensions/rack/server")
|
80
|
+
end
|
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.
|
4
|
+
version: 4.15.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:
|
11
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -80,7 +80,9 @@ files:
|
|
80
80
|
- lib/rails_semantic_logger/extensions/active_support/tagged_logging.rb
|
81
81
|
- lib/rails_semantic_logger/extensions/mongoid/config.rb
|
82
82
|
- lib/rails_semantic_logger/extensions/rack/server.rb
|
83
|
+
- lib/rails_semantic_logger/extensions/rackup/server.rb
|
83
84
|
- lib/rails_semantic_logger/extensions/rails/server.rb
|
85
|
+
- lib/rails_semantic_logger/extensions/sidekiq/sidekiq.rb
|
84
86
|
- lib/rails_semantic_logger/options.rb
|
85
87
|
- lib/rails_semantic_logger/rack/logger.rb
|
86
88
|
- lib/rails_semantic_logger/version.rb
|
@@ -90,7 +92,7 @@ licenses:
|
|
90
92
|
metadata:
|
91
93
|
bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
|
92
94
|
documentation_uri: https://logger.rocketjob.io
|
93
|
-
source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.
|
95
|
+
source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.15.0
|
94
96
|
rubygems_mfa_required: 'true'
|
95
97
|
post_install_message:
|
96
98
|
rdoc_options: []
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
- !ruby/object:Gem::Version
|
108
110
|
version: '0'
|
109
111
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.5.3
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: Feature rich logging framework that replaces the Rails logger.
|