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

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

Type Parameters

Path

The type representing file paths in the file system

actual class TraceFeatureMessageFileWriter<Path> : <ERROR CLASS> ERROR CLASS: Symbol not found for FeatureMessageFileWriter<Path>(source)

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

targetPath

The path where feature messages will be written.

sinkOpener

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.

format

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

targetPath

The file where feature messages will be written.

sinkOpener

A lambda function that returns a Sink for writing to the file. The lifecycle of the sink is managed by this class.

format

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

Path

The type representing the file path supported by the file system provider.

Constructors

Link copied to clipboard
expect constructor(targetPath: Path, sinkOpener: (Path) -> Sink, format: (FeatureMessage) -> String? = null)
actual constructor(targetPath: Path, sinkOpener: (Path) -> ERROR CLASS: Symbol not found for Sink, format: (ERROR CLASS: Symbol not found for FeatureMessage) -> String?)
actual constructor(targetPath: Path, sinkOpener: (Path) -> Sink, format: (FeatureMessage) -> String?)

Types

Link copied to clipboard
object Companion

Companion object with factories for TraceFeatureMessageFileWriter

Properties

Link copied to clipboard
open override val isOpen: StateFlow<Boolean>
open override val isOpen: StateFlow<Boolean>
Link copied to clipboard
Link copied to clipboard
expect val targetPath: Path

Functions

Link copied to clipboard
open suspend override fun close()
open suspend override fun close()
Link copied to clipboard
open suspend override fun initialize()
open suspend override fun initialize()
Link copied to clipboard
expect suspend fun onMessage(message: FeatureMessage)
suspend fun onMessage(message: FeatureMessage)
Link copied to clipboard
expect fun setMessageFilter(filter: (FeatureMessage) -> Boolean)
Link copied to clipboard
expect open override fun FeatureMessage.toFileString(): String
actual open override fun ERROR CLASS: Symbol not found for FeatureMessage.toFileString(): String
actual open override fun FeatureMessage.toFileString(): String