-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
121464a
commit 370e049
Showing
4 changed files
with
48 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module RailsSemanticLogger | ||
module Sidekiq | ||
module Defaults | ||
# Prevent exception logging during standard error handling since the Job Logger below already logs the exception. | ||
if ::Sidekiq::VERSION.to_f < 7.2 | ||
ERROR_HANDLER = ->(ex, ctx) do | ||
unless ctx.empty? | ||
job_hash = ctx[:job] || {} | ||
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"] | ||
logger = klass ? SemanticLogger[klass] : Sidekiq.logger | ||
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx) | ||
end | ||
end | ||
else | ||
ERROR_HANDLER = ->(ex, ctx, _default_configuration) do | ||
unless ctx.empty? | ||
job_hash = ctx[:job] || {} | ||
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"] | ||
logger = klass ? SemanticLogger[klass] : Sidekiq.logger | ||
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx) | ||
end | ||
end | ||
end | ||
|
||
# Returns the default logger after removing from the supplied list. | ||
# Returns [nil] when the default logger was not present. | ||
def self.delete_default_error_handler(error_handlers) | ||
return error_handlers.delete(::Sidekiq::Config::ERROR_HANDLER) if defined?(::Sidekiq::Config::ERROR_HANDLER) | ||
return error_handlers.delete(::Sidekiq::DEFAULT_ERROR_HANDLER) if defined?(::Sidekiq::DEFAULT_ERROR_HANDLER) | ||
|
||
return unless defined?(::Sidekiq::ExceptionHandler) | ||
existing = error_handlers.find { |handler| handler.is_a?(::Sidekiq::ExceptionHandler::Logger) } | ||
return config.error_handlers.delete(existing) if existing | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# In tests we force Sidekiq into thinking it is running as a server, | ||
# so it creates a stdout logger. Remove it here: | ||
Rails.application.config.after_initialize do | ||
if Rails.env.test? | ||
SemanticLogger.appenders.delete_if { |appender| appender.is_a?(SemanticLogger::Appender::IO) } | ||
end | ||
end |