Logging
The SDK provides a structured logging system with configurable log levels, formats, colors, and output streams. Configuration is driven by environment variables (see Environment Variables) and can be overridden programmatically.
Logger
Structured logger that respects global level, format, and color settings. Each Logger has a name and optional bound context data included in every entry.
Parameters
name
Logger name shown in log output (e.g., "AgentBase", "SessionManager").
context
Optional key-value pairs included in every log entry from this logger.
debug / info / warn / error
Log a message at the given severity level.
msg
The log message.
data
Optional structured data to include in the log entry.
bind
Create a child logger with additional bound context fields merged into the parent’s context.
context
Key-value pairs to merge into the child logger’s context.
Returns: Logger — A new Logger instance with the merged context.
getLogger
Create or retrieve a cached Logger instance by name.
Parameters
name
Logger name. Instances are cached — calling getLogger('foo') twice returns the same Logger.
Returns
Logger
Example
setGlobalLogLevel
Set the minimum log level for all loggers. Messages below this level are suppressed.
Parameters
level
The minimum severity level to emit.
Returns
void
Example
suppressAllLogs
Suppress or restore all log output globally.
Parameters
suppress
true to suppress all output, false to restore.
Returns
void
Example
setGlobalLogFormat
Set the output format for all loggers.
Parameters
format
"text" for human-readable output with colors, "json" for structured JSON entries.
Returns
void
Example
setGlobalLogColor
Enable or disable ANSI color codes in text-format output.
Parameters
enabled
true to enable colors, false to disable.
Returns
void
Example
setGlobalLogStream
Set the output stream for all loggers.
Parameters
stream
The output stream to use.
Returns
void
Example
resetLoggingConfiguration
Reset all logging settings to their environment-variable-based defaults and clear the logger cache.
Parameters
None.
Returns
void
Example
getExecutionMode
Detect the execution environment by inspecting well-known environment variables.
Parameters
None.
Returns
[string, 'off' | 'stderr' | 'default'] — A tuple of [environment_name, derived_log_mode].