rails_semantic_logger 4.19.0 → 4.20.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 +4 -4
- data/Rakefile +2 -2
- data/lib/rails_semantic_logger/active_job/log_subscriber.rb +2 -0
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +12 -16
- data/lib/rails_semantic_logger/engine.rb +4 -2
- data/lib/rails_semantic_logger/extensions/sidekiq/sidekiq.rb +29 -12
- data/lib/rails_semantic_logger/options.rb +19 -13
- data/lib/rails_semantic_logger/sidekiq/job_logger.rb +30 -12
- data/lib/rails_semantic_logger/version.rb +1 -1
- metadata +9 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8f7b94b3d6d4f231657586789b55ffe22c4a3d86e7f34c558b5c757a6e3d2af
|
|
4
|
+
data.tar.gz: 72a661f99dae0261b5cd6c6dffe972bfee3903ea48dd3b16832d40aa747bc9c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae75985892a47040a291e94fed73756884aca9c74e21339b3d40fba964bad47b6ffa5237899cb34b05d7c8727e9a9ebe8967774b3693cc9d9371ef61d3696814
|
|
7
|
+
data.tar.gz: 1601458b40ab94c03244b44aed2522f1c0a72f06076f9df46f42793de77f10ccff63d7f851be38a984eae9615fe7ca977141b50f473a282d9e1adf15e864665d
|
data/Rakefile
CHANGED
|
@@ -10,8 +10,8 @@ task :gem do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
task publish: :gem do
|
|
13
|
-
system "git tag -a v#{RailsSemanticLogger::VERSION} -m 'Tagging #{RailsSemanticLogger::VERSION}'"
|
|
14
|
-
system "git push --tags"
|
|
13
|
+
# system "git tag -a v#{RailsSemanticLogger::VERSION} -m 'Tagging #{RailsSemanticLogger::VERSION}'"
|
|
14
|
+
# system "git push --tags"
|
|
15
15
|
system "gem push rails_semantic_logger-#{RailsSemanticLogger::VERSION}.gem"
|
|
16
16
|
system "rm rails_semantic_logger-#{RailsSemanticLogger::VERSION}.gem"
|
|
17
17
|
end
|
|
@@ -2,34 +2,30 @@ module RailsSemanticLogger
|
|
|
2
2
|
module ActiveRecord
|
|
3
3
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
|
4
4
|
IGNORE_PAYLOAD_NAMES = %w[SCHEMA EXPLAIN].freeze
|
|
5
|
-
RAILS_VERSION_ENDING_SET_RUNTIME_SUPPORT = Gem::Version.new( "8.0.3")
|
|
6
5
|
|
|
7
6
|
class << self
|
|
8
7
|
attr_reader :logger
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
::ActiveRecord::RuntimeRegistry.respond_to?(:stats) ?
|
|
15
|
-
::ActiveRecord::RuntimeRegistry.stats.sql_runtime = value :
|
|
10
|
+
# Rails 7.1 stopped using runtime in log subscribers
|
|
11
|
+
if Rails.version.to_f < 7.1
|
|
12
|
+
def self.runtime=(value)
|
|
16
13
|
::ActiveRecord::RuntimeRegistry.sql_runtime = value
|
|
17
|
-
|
|
14
|
+
end
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
::ActiveRecord::RuntimeRegistry.respond_to?(:stats) ?
|
|
21
|
-
::ActiveRecord::RuntimeRegistry.stats.sql_runtime ||= 0 :
|
|
16
|
+
def self.runtime
|
|
22
17
|
::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
|
|
23
|
-
|
|
18
|
+
end
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
def self.reset_runtime
|
|
21
|
+
rt = runtime
|
|
22
|
+
self.runtime = 0
|
|
23
|
+
rt
|
|
24
|
+
end
|
|
29
25
|
end
|
|
30
26
|
|
|
31
27
|
def sql(event)
|
|
32
|
-
self.class.runtime += event.duration
|
|
28
|
+
self.class.runtime += event.duration if self.class.respond_to?(:runtime)
|
|
33
29
|
return unless logger.debug?
|
|
34
30
|
|
|
35
31
|
payload = event.payload
|
|
@@ -108,7 +108,7 @@ module RailsSemanticLogger
|
|
|
108
108
|
Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger=)
|
|
109
109
|
|
|
110
110
|
# Replace the Sidekiq logger
|
|
111
|
-
if defined?(::Sidekiq)
|
|
111
|
+
if config.rails_semantic_logger.replace_sidekiq_logger && defined?(::Sidekiq)
|
|
112
112
|
::Sidekiq.configure_client do |config|
|
|
113
113
|
config.logger = ::SemanticLogger[::Sidekiq]
|
|
114
114
|
end
|
|
@@ -245,7 +245,9 @@ module RailsSemanticLogger
|
|
|
245
245
|
)
|
|
246
246
|
end
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
if config.rails_semantic_logger.replace_sidekiq_logger && defined?(::Sidekiq)
|
|
249
|
+
require("rails_semantic_logger/extensions/sidekiq/sidekiq")
|
|
250
|
+
end
|
|
249
251
|
end
|
|
250
252
|
|
|
251
253
|
#
|
|
@@ -44,24 +44,41 @@ module Sidekiq
|
|
|
44
44
|
# rubocop:disable Style/ExplicitBlockArgument
|
|
45
45
|
def call(worker, item, queue)
|
|
46
46
|
SemanticLogger.tagged(queue: queue) do
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
if perform_messages_enabled?
|
|
48
|
+
worker.logger.info(
|
|
49
|
+
"Start #perform",
|
|
50
|
+
metric: "sidekiq.queue.latency",
|
|
51
|
+
metric_amount: job_latency_ms(item)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
worker.logger.measure_info(
|
|
55
|
+
"Completed #perform",
|
|
56
|
+
on_exception_level: :error,
|
|
57
|
+
log_exception: :full,
|
|
58
|
+
metric: "sidekiq.job.perform"
|
|
59
|
+
) { yield }
|
|
60
|
+
else
|
|
61
|
+
yield
|
|
62
|
+
end
|
|
58
63
|
end
|
|
59
64
|
end
|
|
60
65
|
|
|
66
|
+
def perform_messages_enabled?
|
|
67
|
+
RailsSemanticLogger::Sidekiq::JobLogger.perform_messages != false
|
|
68
|
+
end
|
|
69
|
+
|
|
61
70
|
def job_latency_ms(job)
|
|
62
71
|
return unless job && job["enqueued_at"]
|
|
63
72
|
|
|
64
|
-
|
|
73
|
+
enqueued_at = job["enqueued_at"]
|
|
74
|
+
if enqueued_at.is_a?(Float)
|
|
75
|
+
# Sidekiq <= 7: seconds since epoch
|
|
76
|
+
(Time.now.to_f - enqueued_at) * 1000
|
|
77
|
+
else
|
|
78
|
+
# Sidekiq 8+: milliseconds since epoch
|
|
79
|
+
now = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
|
|
80
|
+
now - enqueued_at
|
|
81
|
+
end
|
|
65
82
|
end
|
|
66
83
|
end
|
|
67
84
|
end
|
|
@@ -108,24 +108,30 @@ module RailsSemanticLogger
|
|
|
108
108
|
# config.rails_semantic_logger.action_message_format = -> (message, payload) do
|
|
109
109
|
# "#{message} - #{payload[:controller]}##{payload[:action]}"
|
|
110
110
|
# end
|
|
111
|
+
#
|
|
112
|
+
# * Do not replace the Sidekiq logger with a Semantic Logger logger.
|
|
113
|
+
#
|
|
114
|
+
# config.rails_semantic_logger.replace_sidekiq_logger = false
|
|
111
115
|
class Options
|
|
112
116
|
attr_accessor :semantic, :started, :processing, :rendered, :ap_options, :add_file_appender,
|
|
113
|
-
:quiet_assets, :format, :named_tags, :filter, :console_logger, :action_message_format
|
|
117
|
+
:quiet_assets, :format, :named_tags, :filter, :console_logger, :action_message_format,
|
|
118
|
+
:replace_sidekiq_logger
|
|
114
119
|
|
|
115
120
|
# Setup default values
|
|
116
121
|
def initialize
|
|
117
|
-
@semantic
|
|
118
|
-
@started
|
|
119
|
-
@processing
|
|
120
|
-
@rendered
|
|
121
|
-
@ap_options
|
|
122
|
-
@add_file_appender
|
|
123
|
-
@quiet_assets
|
|
124
|
-
@format
|
|
125
|
-
@named_tags
|
|
126
|
-
@filter
|
|
127
|
-
@console_logger
|
|
128
|
-
@action_message_format
|
|
122
|
+
@semantic = true
|
|
123
|
+
@started = false
|
|
124
|
+
@processing = false
|
|
125
|
+
@rendered = false
|
|
126
|
+
@ap_options = {multiline: false}
|
|
127
|
+
@add_file_appender = true
|
|
128
|
+
@quiet_assets = false
|
|
129
|
+
@format = :default
|
|
130
|
+
@named_tags = nil
|
|
131
|
+
@filter = nil
|
|
132
|
+
@console_logger = true
|
|
133
|
+
@action_message_format = nil
|
|
134
|
+
@replace_sidekiq_logger = true
|
|
129
135
|
end
|
|
130
136
|
end
|
|
131
137
|
end
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
module RailsSemanticLogger
|
|
2
2
|
module Sidekiq
|
|
3
3
|
class JobLogger
|
|
4
|
+
class << self
|
|
5
|
+
attr_writer :perform_messages
|
|
6
|
+
|
|
7
|
+
def perform_messages
|
|
8
|
+
instance_variable_defined?(:@perform_messages) ? @perform_messages : true
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
4
12
|
# Sidekiq 6.5 does not take any arguments, whereas v7 is given a logger
|
|
5
13
|
def initialize(*_args)
|
|
6
14
|
end
|
|
@@ -10,21 +18,27 @@ module RailsSemanticLogger
|
|
|
10
18
|
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
|
11
19
|
|
|
12
20
|
SemanticLogger.tagged(queue: queue) do
|
|
21
|
+
if perform_messages_enabled?
|
|
13
22
|
# Latency is the time between when the job was enqueued and when it started executing.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
logger.info(
|
|
24
|
+
"Start #perform",
|
|
25
|
+
metric: "sidekiq.queue.latency",
|
|
26
|
+
metric_amount: job_latency_ms(item)
|
|
27
|
+
)
|
|
28
|
+
end
|
|
19
29
|
|
|
20
30
|
# Measure the duration of running the job
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
if perform_messages_enabled?
|
|
32
|
+
logger.measure_info(
|
|
33
|
+
"Completed #perform",
|
|
34
|
+
on_exception_level: :error,
|
|
35
|
+
log_exception: :full,
|
|
36
|
+
metric: "sidekiq.job.perform",
|
|
37
|
+
&block
|
|
38
|
+
)
|
|
39
|
+
else
|
|
40
|
+
yield if block_given?
|
|
41
|
+
end
|
|
28
42
|
end
|
|
29
43
|
end
|
|
30
44
|
|
|
@@ -41,6 +55,10 @@ module RailsSemanticLogger
|
|
|
41
55
|
|
|
42
56
|
private
|
|
43
57
|
|
|
58
|
+
def perform_messages_enabled?
|
|
59
|
+
self.class.perform_messages != false
|
|
60
|
+
end
|
|
61
|
+
|
|
44
62
|
def job_hash_context(job_hash)
|
|
45
63
|
h = {jid: job_hash["jid"]}
|
|
46
64
|
h[:bid] = job_hash["bid"] if job_hash["bid"]
|
metadata
CHANGED
|
@@ -1,13 +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.20.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Reid Morrison
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-04-10 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: rack
|
|
@@ -51,6 +52,8 @@ dependencies:
|
|
|
51
52
|
- - "~>"
|
|
52
53
|
- !ruby/object:Gem::Version
|
|
53
54
|
version: '4.16'
|
|
55
|
+
description:
|
|
56
|
+
email:
|
|
54
57
|
executables: []
|
|
55
58
|
extensions: []
|
|
56
59
|
extra_rdoc_files: []
|
|
@@ -92,8 +95,9 @@ licenses:
|
|
|
92
95
|
metadata:
|
|
93
96
|
bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
|
|
94
97
|
documentation_uri: https://logger.rocketjob.io
|
|
95
|
-
source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.
|
|
98
|
+
source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.20.0
|
|
96
99
|
rubygems_mfa_required: 'true'
|
|
100
|
+
post_install_message:
|
|
97
101
|
rdoc_options: []
|
|
98
102
|
require_paths:
|
|
99
103
|
- lib
|
|
@@ -108,7 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
108
112
|
- !ruby/object:Gem::Version
|
|
109
113
|
version: '0'
|
|
110
114
|
requirements: []
|
|
111
|
-
rubygems_version: 3.
|
|
115
|
+
rubygems_version: 3.4.19
|
|
116
|
+
signing_key:
|
|
112
117
|
specification_version: 4
|
|
113
118
|
summary: Feature rich logging framework that replaces the Rails logger.
|
|
114
119
|
test_files: []
|