TraceFeatureMessageFileWriter
A message processor that writes trace events to a file.
This writer captures all trace events and writes them to a specified file using the provided file system. It formats each event type differently to provide clear and readable logs.
Tracing to files is particularly useful for:
Persistent logging that survives application restarts
Detailed analysis of agent behavior after execution
Sharing trace logs with other developers or systems
Example usage:
val agent = AIAgent(...) {
install(Tracing) {
// Write trace events to a file
addMessageProcessor(TraceFeatureMessageFileWriter(
sinkOpener = fileSystem::sink,
targetPath = "agent-traces.log"
))
// Optionally provide custom formatting
addMessageProcessor(TraceFeatureMessageFileWriter(
sinkOpener = fileSystem::sink,
targetPath = "custom-traces.log",
format = { message ->
"[TRACE] ${message::class.simpleName}"
}
))
}
}Parameters
The path where feature messages will be written.
Returns a Sink for writing to the file, this class manages its lifecycle.
Optional custom formatter for trace events
Type Parameters
The type representing file paths in the file system
A specialized implementation of FeatureMessageFileWriter for tracing and writing feature messages to a target file, with customizable formatting and sink handling.
This class supports writing feature messages to a file using a specified sink opener and an optional formatting function. It serves as an adapter for delegating the core functionality to TraceFeatureMessageFileWriterImpl.
Parameters
The path where feature messages will be written.
A function responsible for opening a Sink for file writing. This function ensures the lifecycle of the sink is properly managed. A default sink opener is available if not provided.
An optional lambda function for customizing the formatting of FeatureMessage instances before writing them to the file. If not provided, a default formatting strategy is used.
A specialized implementation of FeatureMessageFileWriter designed for handling trace-related feature messages. This class facilitates writing trace-specific feature messages to a file, supporting custom formatting logic if needed.
Parameters
The file where feature messages will be written.
A lambda function that returns a Sink for writing to the file. The lifecycle of the sink is managed by this class.
An optional lambda function for custom formatting of FeatureMessage instances into their string representations. This can be used to apply specific serialization logic if required. If not provided, the default message trace representation is used.
Type Parameters
The type representing the file path supported by the file system provider.
Constructors
Types
Companion object with factories for TraceFeatureMessageFileWriter