Class: RosettAi::StructuredLogger
- Inherits:
-
Logger
- Object
- Logger
- RosettAi::StructuredLogger
- Defined in:
- lib/rosett_ai/structured_logger.rb
Overview
Structured logger with per-invocation correlation IDs and JSON/text output.
Drop-in replacement for Ruby's +Logger+. Every log entry includes a correlation ID (UUID v4) generated once per CLI invocation so that all entries from one run can be correlated.
Log format is controlled by +RAI_LOG_FORMAT+:
- +"text"+ (default): [LEVEL] [correlation_id] message
- +"json"+: JSON Lines (one JSON object per line)
Constant Summary collapse
- VALID_FORMATS =
['text', 'json'].freeze
Instance Attribute Summary collapse
-
#command ⇒ String?
Current command name (set via #command=).
-
#correlation_id ⇒ String
readonly
Correlation ID for the current invocation (UUID v4).
Instance Method Summary collapse
-
#initialize(output = $stderr, correlation_id: nil) ⇒ StructuredLogger
constructor
Creates a new structured logger writing to stderr.
-
#reset!
Reset logger state.
Constructor Details
#initialize(output = $stderr, correlation_id: nil) ⇒ StructuredLogger
Creates a new structured logger writing to stderr.
42 43 44 45 46 47 48 49 50 |
# File 'lib/rosett_ai/structured_logger.rb', line 42 def initialize(output = $stderr, correlation_id: nil) super(output) @correlation_id = correlation_id || SecureRandom.uuid @command = nil @mutex = Mutex.new self.level = resolve_level self.formatter = build_formatter end |
Instance Attribute Details
#command ⇒ String?
Returns current command name (set via #command=).
36 37 38 |
# File 'lib/rosett_ai/structured_logger.rb', line 36 def command @command end |
#correlation_id ⇒ String (readonly)
Returns correlation ID for the current invocation (UUID v4).
33 34 35 |
# File 'lib/rosett_ai/structured_logger.rb', line 33 def correlation_id @correlation_id end |
Instance Method Details
#reset!
This method returns an undefined value.
Reset logger state. Generates a new correlation ID. Intended for test isolation.
64 65 66 67 68 69 |
# File 'lib/rosett_ai/structured_logger.rb', line 64 def reset! @mutex.synchronize do @correlation_id = SecureRandom.uuid @command = nil end end |