Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Ability to be Able to Configure the Logger #772

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/shoryuken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def self.healthy?
:exception_handlers=,
:options,
:logger,
:logger=,
:register_worker,
:configure_server,
:server?,
Expand Down
2 changes: 1 addition & 1 deletion lib/shoryuken/extensions/active_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module QueueAdapters
# To use Shoryuken set the queue_adapter config to +:shoryuken+.
#
# Rails.application.config.active_job.queue_adapter = :shoryuken
class ShoryukenAdapter
class ShoryukenAdapter < ActiveJob::QueueAdapters::AbstractAdapter
class << self
def instance
# https://github.com/phstc/shoryuken/pull/174#issuecomment-174555657
Expand Down
20 changes: 16 additions & 4 deletions lib/shoryuken/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

module Shoryuken
module Logging
class Pretty < Logger::Formatter
# Provide a call() method that returns the formatted message.
def call(severity, time, _program_name, message)
"#{time.utc.iso8601} #{Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{context} #{severity}: #{message}\n"
class Base < ::Logger::Formatter
def tid
Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
end

def context
Expand All @@ -15,6 +14,19 @@ def context
end
end

class Pretty < Base
# Provide a call() method that returns the formatted message.
def call(severity, time, _program_name, message)
"#{time.utc.iso8601} #{Process.pid} TID-#{tid}#{context} #{severity}: #{message}\n"
end
end

class WithoutTimestamp < Base
def call(severity, _time, _program_name, message)
"pid=#{Process.pid} tid=#{tid}#{context} #{severity}: #{message}\n"
end
end

def self.with_context(msg)
Thread.current[:shoryuken_context] = msg
yield
Expand Down
12 changes: 7 additions & 5 deletions lib/shoryuken/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class Options
}
}.freeze

attr_accessor :active_job_queue_name_prefixing, :cache_visibility_timeout, :groups,
:launcher_executor, :reloader, :enable_reloading,
:start_callback, :stop_callback, :worker_executor, :worker_registry, :exception_handlers
attr_writer :default_worker_options, :sqs_client
attr_accessor :active_job_queue_name_prefixing, :cache_visibility_timeout,
:groups, :launcher_executor, :reloader, :enable_reloading,
:start_callback, :stop_callback, :worker_executor, :worker_registry,
:exception_handlers

attr_writer :default_worker_options, :sqs_client, :logger
attr_reader :sqs_client_receive_message_opts

def initialize
Expand Down Expand Up @@ -95,7 +97,7 @@ def options
end

def logger
Shoryuken::Logging.logger
@logger ||= Shoryuken::Logging.logger
end

def register_worker(*args)
Expand Down