Class: Shoryuken::Logging::Base

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/shoryuken/logging/base.rb

Overview

Base formatter class that provides common functionality for Shoryuken log formatters. Provides thread ID generation and context management.

Direct Known Subclasses

Pretty, WithoutTimestamp

Instance Method Summary collapse

Instance Method Details

#contextString

Returns the current logging context as a formatted string. Context is set using Shoryuken::Logging.with_context.

Returns:

  • (String)

    Formatted context string or empty string if no context



20
21
22
23
# File 'lib/shoryuken/logging/base.rb', line 20

def context
  c = Thread.current[:shoryuken_context]
  c ? " #{c}" : ''
end

#tidString

Generates a thread ID for the current thread. Uses a combination of thread object_id and process ID to create a unique identifier.

Returns:

  • (String)

    A base36-encoded thread identifier



12
13
14
# File 'lib/shoryuken/logging/base.rb', line 12

def tid
  Thread.current['shoryuken_tid'] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
end