TraceFeatureMessageLogWriter
A message processor that writes trace events to a logger.
This writer captures all trace events and writes them to the specified logger at the configured log level. It formats each event type differently to provide clear and readable logs.
Tracing to logs is particularly useful for:
Integration with existing logging infrastructure
Real-time monitoring of agent behavior
Filtering and searching trace events using log management tools
Example usage:
// Create a logger
val logger = LoggerFactory.create("ai.koog.agents.tracing")
val agent = AIAgent(...) {
install(Tracing) {
// Write trace events to logs at INFO level (default)
addMessageProcessor(TraceFeatureMessageLogWriter(logger))
// Write trace events to logs at DEBUG level
addMessageProcessor(TraceFeatureMessageLogWriter(
targetLogger = logger,
logLevel = LogLevel.DEBUG
))
// Optionally provide custom formatting
addMessageProcessor(TraceFeatureMessageLogWriter(
targetLogger = logger,
format = { message ->
"[TRACE] ${message::class.simpleName}"
}
))
}
}Parameters
The logger to write trace events to
The log level to use for trace events (default: INFO)
Optional custom formatter for trace events
Implementation of FeatureMessageLogWriter that handles logging of feature messages with trace-level detail using a standardized or custom log message format.
Parameters
The KLogger instance to output trace logs.
The log level used for trace events. Defaults to LogLevel.INFO.
A lambda function for custom formatting of FeatureMessage into a loggable string, or null to use a default format.
A concrete implementation of FeatureMessageLogWriter that handles logging of feature messages specifically for trace-level operations.
This class utilizes a delegate implementation, TraceFeatureMessageLogWriterImpl, to handle the formatting and processing of messages while maintaining a consistent API.
Parameters
The KLogger instance used for logging feature messages.
The level at which messages will be logged. Defaults to LogLevel.INFO.
An optional lambda used to format FeatureMessage instances into strings for logging. If not provided, a default implementation will be used.
Constructors
Initializes an instance of TraceFeatureMessageLogWriter.
Creates an instance with the specified logger, log level, and optional message formatter.
Types
Companion object with factories for TraceFeatureMessageLogWriter