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 =
Returns Supported structured log output 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! ⇒ void
Reset logger state.
Constructor Details
#initialize(output = $stderr, correlation_id: nil) ⇒ StructuredLogger
Creates a new structured logger writing to stderr.
43 44 45 46 47 48 49 50 51 |
# File 'lib/rosett_ai/structured_logger.rb', line 43 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=).
37 38 39 |
# File 'lib/rosett_ai/structured_logger.rb', line 37 def command @command end |
#correlation_id ⇒ String (readonly)
Returns correlation ID for the current invocation (UUID v4).
34 35 36 |
# File 'lib/rosett_ai/structured_logger.rb', line 34 def correlation_id @correlation_id end |
Instance Method Details
#reset! ⇒ void
This method returns an undefined value.
Reset logger state. Generates a new correlation ID. Intended for test isolation.
65 66 67 68 69 70 |
# File 'lib/rosett_ai/structured_logger.rb', line 65 def reset! @mutex.synchronize do @correlation_id = SecureRandom.uuid @command = nil end end |