Skip to content

Commit

Permalink
add a without timestamp class
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorganMY committed Jul 25, 2024
1 parent 7ef2d2a commit a2cb658
Showing 1 changed file with 16 additions and 4 deletions.
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

0 comments on commit a2cb658

Please sign in to comment.