FateLogWriter

A writer for FateWeaver log files that supports multiple typed channels.

FateLogWriter provides a high-performance binary logging format with the following features:

  • Type Safety: Each channel is strongly typed with compile-time guarantees

  • Schema Evolution: Schemas are embedded in the log file for compatibility

  • Multiple Channels: Different data types can be logged to separate named channels

  • Efficient Encoding: Binary format optimized for size and speed

  • Auto-Schema Detection: Can automatically infer schemas from class types

File Format

Each log file begins with a header containing magic bytes and version information, followed by a series of entries. There are two types of entries:

  1. Schema Entries (type 0): Define the structure of a channel

  2. Message Entries (type 1): Contain the actual logged data

Usage Example

// Create a log writer
FateLogWriter.create("mylog.fate").use { writer ->
// Create typed channels
val userChannel = writer.createChannel("users", User::class)
val eventChannel = writer.createChannel("events", Event::class)

// Write data
userChannel.put(User("alice", 25))
eventChannel.put(Event("login", System.currentTimeMillis()))
}

Parameters

stream

The output stream to write the log data to

Constructors

Link copied to clipboard
constructor(stream: OutputStream)

Creates a new FateLogWriter that writes to the specified stream

Types

Link copied to clipboard
object Companion
Link copied to clipboard
inner class WriterChannel<T> : LogChannel<T>

A log channel implementation that is bound to a specific FateLogWriter.

Properties

Link copied to clipboard

Functions

Link copied to clipboard

Adds a channel to the log and immediately writes its schema definition.

Adds a channel to the log, creating a WriterChannel from the given LogChannel if necessary.

Link copied to clipboard
open override fun close()

Closes the log writer and flushes any remaining data to the underlying stream.

Link copied to clipboard
operator fun contains(channel: LogChannel<*>): <Error class: unknown class>

Checks if a channel with the same name as the provided channel exists in this writer.

Link copied to clipboard

Creates a new log channel with the specified name and schema, and adds it to the log.

fun <T : Any> createChannel(name: String, cls: KClass<T>): <Error class: unknown class>

Creates a new log channel with the specified name and automatically inferred schema.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun <T> write(channel: LogChannel<T>, obj: T)

Writes an object to the specified channel.

fun write(channelName: String, obj: Any)

Writes an object to a channel identified by name.