diff --git a/bin/outboxer_publisher b/bin/outboxer_publisher index 1442ca2..31c3e9e 100755 --- a/bin/outboxer_publisher +++ b/bin/outboxer_publisher @@ -13,7 +13,7 @@ options = { poll: ENV.fetch('OUTBOXER_POLL', 5.0).to_f, tick: ENV.fetch('OUTBOXER_TICK', 0.1).to_f, heartbeat: ENV.fetch('OUTBOXER_HEARTBEAT', 5.0).to_f, - log_level: ENV.fetch('OUTBOXER_LOG_LEVEL', 'info').downcase, + log_level: ENV.fetch('OUTBOXER_LOG_LEVEL', 'INFO'), sidekiq_redis_url: ENV.fetch('SIDEKIQ_REDIS_URL', 'redis://localhost:6379/0') } @@ -21,8 +21,7 @@ Sidekiq.configure_client do |config| config.redis = { url: options[:sidekiq_redis_url], size: options[:concurrency] } end -logger = Sidekiq.logger -logger.level = Logger.const_get(options[:log_level].upcase) +logger = Outboxer::Logger.new($stdout, level: options[:log_level]) Outboxer::Publisher.publish( env: options[:env], @@ -31,12 +30,13 @@ Outboxer::Publisher.publish( poll: options[:poll], tick: options[:tick], heartbeat: options[:heartbeat], - logger: logger, + logger: logger ) do |message| case message[:messageable_type] when 'Event' EventCreatedJob.perform_async({ 'id' => message[:messageable_id] }) + + logger.info "Outboxer published message #{message[:id]} for "\ + "#{message[:messageable_type]}::#{message[:messageable_id]} "\ end end - -# bin/outboxer_publisher diff --git a/lib/outboxer/logger.rb b/lib/outboxer/logger.rb index 87cd2ee..9dd6848 100644 --- a/lib/outboxer/logger.rb +++ b/lib/outboxer/logger.rb @@ -6,11 +6,14 @@ def initialize(*args, **kwargs) super(*args, **kwargs) self.formatter = proc do |severity, datetime, progname, msg| - formatted_time = datetime.strftime('%Y-%m-%dT%H:%M:%S.%LZ') - pid = Process.pid - tid = Thread.current.object_id.to_s(36) - level = severity - "#{formatted_time} pid=#{pid} tid=#{tid} #{level}: #{msg}\n" + current_thread = ::Thread.current + + pid = current_thread['outboxer_pid'] ||= ::Process.pid + + tid = current_thread["outboxer_tid"] ||= + (current_thread.name || (current_thread.object_id ^ pid).to_s(36)) + + "#{datetime.utc.iso8601(3)} pid=#{pid} tid=#{tid} #{severity}: #{msg}\n" end end end diff --git a/spec/lib/outboxer/logger_spec.rb b/spec/lib/outboxer/logger_spec.rb index 7c863a1..63c0a1e 100644 --- a/spec/lib/outboxer/logger_spec.rb +++ b/spec/lib/outboxer/logger_spec.rb @@ -5,7 +5,8 @@ module Outboxer RSpec.describe Logger do let(:output) { StringIO.new } - let(:logger) { Logger.new(output) } + let(:level) { 'info' } + let(:logger) { Logger.new(output, level: Logger.const_get(level.upcase)) } describe 'logging' do it 'logs messages with correct format' do