TraceFeatureMessageFileWriter

class TraceFeatureMessageFileWriter<Path>(targetPath: Path, sinkOpener: (Path) -> Sink, format: (FeatureMessage) -> String? = null) : FeatureMessageFileWriter<Path> (source)

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.eventId}: ${message::class.simpleName}"
}
))
}
}

Parameters

Path

The type representing file paths in the file system

targetPath

The path where feature messages will be written.

sinkOpener

Returns a Sink for writing to the file, this class manages its lifecycle.

format

Optional custom formatter for trace events

Constructors

Link copied to clipboard
constructor(targetPath: Path, sinkOpener: (Path) -> Sink, format: (FeatureMessage) -> String? = null)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
open suspend override fun initialize()
Link copied to clipboard
open suspend override fun processMessage(message: FeatureMessage)
Link copied to clipboard
open override fun FeatureMessage.toFileString(): String