Module: Shoryuken::Logging
- Defined in:
- lib/shoryuken/logging.rb,
lib/shoryuken/logging/base.rb,
lib/shoryuken/logging/pretty.rb,
lib/shoryuken/logging/without_timestamp.rb
Overview
Provides logging functionality for Shoryuken. Manages the global logger instance and fiber-local context.
Defined Under Namespace
Classes: Base, Pretty, WithoutTimestamp
Class Method Summary collapse
-
.context_storage ⇒ Class
Returns the Fiber class for fiber-local context storage.
-
.current_context ⇒ String?
Returns the current logging context value.
-
.initialize_logger(log_target = STDOUT) ⇒ Logger
Initializes a new logger instance.
-
.logger ⇒ Logger
Returns the current logger instance, initializing if needed.
-
.logger=(log) ⇒ Logger
Sets the logger instance.
-
.with_context(msg) { ... } ⇒ Object
Executes a block with a fiber-local logging context.
Class Method Details
.context_storage ⇒ Class
Returns the Fiber class for fiber-local context storage. Uses Fiber[] and Fiber[]= (Ruby 3.2+) for proper isolation in async environments.
38 39 40 |
# File 'lib/shoryuken/logging.rb', line 38 def self.context_storage Fiber end |
.current_context ⇒ String?
Returns the current logging context value
30 31 32 |
# File 'lib/shoryuken/logging.rb', line 30 def self.current_context context_storage[:shoryuken_context] end |
.initialize_logger(log_target = STDOUT) ⇒ Logger
Initializes a new logger instance
46 47 48 49 50 51 |
# File 'lib/shoryuken/logging.rb', line 46 def self.initialize_logger(log_target = STDOUT) @logger = Logger.new(log_target) @logger.level = Logger::INFO @logger.formatter = Pretty.new @logger end |
.logger ⇒ Logger
Returns the current logger instance, initializing if needed
56 57 58 |
# File 'lib/shoryuken/logging.rb', line 56 def self.logger @logger ||= initialize_logger end |
.logger=(log) ⇒ Logger
Sets the logger instance
64 65 66 |
# File 'lib/shoryuken/logging.rb', line 64 def self.logger=(log) @logger = log || Logger.new('/dev/null') end |
.with_context(msg) { ... } ⇒ Object
Executes a block with a fiber-local logging context. Uses Fiber storage (Ruby 3.2+) for proper isolation in async environments.
19 20 21 22 23 24 25 |
# File 'lib/shoryuken/logging.rb', line 19 def self.with_context(msg) previous = context_storage[:shoryuken_context] context_storage[:shoryuken_context] = msg yield ensure context_storage[:shoryuken_context] = previous end |