rails_semantic_logger 4.14.0 → 4.15.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: b41a1fee07d074d18bcaed7538592f123ecbbbe0f232b52cbca96133654ac256
4
- data.tar.gz: df2d6ef10cb8aa051f56a3b916064d1c51afcc3c9ef6f834c2c26be5a3dfc9b4
3
+ metadata.gz: 3bb41dd02df0dc0dc472a66f83a82146878942a309670d4fb10da64bfdae4bc4
4
+ data.tar.gz: c1463e8da359c87fffc4e7d4e56919609320473fa0702b6a7f9b9fec1bdc5050
5
5
  SHA512:
6
- metadata.gz: 70dec27d9976ae2edfc028bdfd03f51b3eade4cf1562681096ba3a882e2f0aacc9fba893cacd5ac7604f3810b2d6e3b880d2411d78a4372ad5b53ab579e41878
7
- data.tar.gz: 635c69136356a8c3ad62a81e0b2db7e397031878619c381fe52240405c2c0b720b9f4900fc2d2ae886d8c23943f8ebd1649444b35357c6178016bb99f036e7dd
6
+ metadata.gz: 1604cdbeed7b9bda178517f7cd7f72e4721523cf222aa6b0a2dcce36fc77c62807641ca32aef349f91c9e5aa86d04e9202e15adff71e4b5e4e29798a3c9dde16
7
+ data.tar.gz: b0e79372c2111bb823c191595a600c8c4c218e6989249f66c0ec46d66826116abfe2f6c5c761d33ae23f1494e7a74b8299d70b037410570757195115b212dced
@@ -224,6 +224,8 @@ module RailsSemanticLogger
224
224
  :action_mailer
225
225
  )
226
226
  end
227
+
228
+ require("rails_semantic_logger/extensions/sidekiq/sidekiq") if defined?(::Sidekiq)
227
229
  end
228
230
 
229
231
  #
@@ -239,7 +241,7 @@ module RailsSemanticLogger
239
241
  end
240
242
 
241
243
  # Re-open appenders after Resque has forked a worker
242
- Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque)
244
+ Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque.after_fork)
243
245
 
244
246
  # Re-open appenders after Spring has forked a process
245
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
- def log_error(_request, wrapper)
10
- ActiveSupport::Deprecation.silence do
11
- ActionController::Base.logger.fatal(wrapper.exception)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsSemanticLogger
2
- VERSION = "4.14.0".freeze
2
+ VERSION = "4.15.0".freeze
3
3
  end
@@ -67,6 +67,12 @@ end
67
67
  require("rails_semantic_logger/extensions/mongoid/config") if defined?(Mongoid)
68
68
  require("rails_semantic_logger/extensions/active_support/logger") if defined?(ActiveSupport::Logger)
69
69
  require("rails_semantic_logger/extensions/active_support/log_subscriber") if defined?(ActiveSupport::LogSubscriber)
70
+
71
+ begin
72
+ require 'rackup'
73
+ rescue LoadError
74
+ # No need to do anything, will fall back to Rack
75
+ end
70
76
  if defined?(Rackup::Server)
71
77
  require("rails_semantic_logger/extensions/rackup/server")
72
78
  elsif 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.14.0
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: 2023-11-16 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -82,6 +82,7 @@ files:
82
82
  - lib/rails_semantic_logger/extensions/rack/server.rb
83
83
  - lib/rails_semantic_logger/extensions/rackup/server.rb
84
84
  - lib/rails_semantic_logger/extensions/rails/server.rb
85
+ - lib/rails_semantic_logger/extensions/sidekiq/sidekiq.rb
85
86
  - lib/rails_semantic_logger/options.rb
86
87
  - lib/rails_semantic_logger/rack/logger.rb
87
88
  - lib/rails_semantic_logger/version.rb
@@ -91,7 +92,7 @@ licenses:
91
92
  metadata:
92
93
  bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
93
94
  documentation_uri: https://logger.rocketjob.io
94
- source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.14.0
95
+ source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.15.0
95
96
  rubygems_mfa_required: 'true'
96
97
  post_install_message:
97
98
  rdoc_options: []
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  requirements: []
111
- rubygems_version: 3.4.9
112
+ rubygems_version: 3.5.3
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: Feature rich logging framework that replaces the Rails logger.