Manuscript Documentation
v2026.12.0

@std/log.ms#

Import each required symbol with import Name from "@std/log.ms".

LogLevel Enum#

Severity levels accepted by a logger, ordered from Trace through Fatal.

Manuscript
enum LogLevel {
    Trace
    Debug
    Info
    Warn
    Error
    Fatal
    Silent
}

LogLevel.Debug#

Development diagnostics, encoded with numeric level 20.

Manuscript
Debug

LogLevel.Error#

Failure records, encoded with numeric level 50.

Manuscript
Error

LogLevel.Fatal#

Critical records at numeric level 60; logging does not terminate the process.

Manuscript
Fatal

LogLevel.Info#

Ordinary operational records, encoded with numeric level 30; the default threshold.

Manuscript
Info

LogLevel.Silent#

Filtering threshold that disables all records; passing it to log returns EINVAL.

Manuscript
Silent

LogLevel.Trace#

Most detailed records, encoded with numeric level 10.

Manuscript
Trace

LogLevel.Warn#

Warning records, encoded with numeric level 40.

Manuscript
Warn

Logger Type#

A structured logger: level filtering, bound fields, and a pluggable Transport. The level methods take optional fields of any Data type and encode them with stringify. A child logger owns a duplicate of the transport (its own handle on the same destination), so loggers can write from several threads and closing one leaves the others open.

Manuscript
opaque type Logger {
}

Logger.child#

Returns a logger that writes fields under context in each record. A child of a child merges object members, and the newer value wins on a clash; if either side is not an object, the newer value replaces the older one. A value that cannot be encoded returns EBADMSG.

Manuscript
fn child[F Data](fields F) Result[Logger, Error]

Logger.close#

Closes this logger’s transport and consumes the logger. A scope that owns a logger should close it on every exit. Children and the parent are not affected.

Manuscript
move fn close() Result[Void, Error]

Logger.debug#

Logs at Debug when enabled, for development diagnostics. Fields are encoded as in log.

Manuscript
fn debug[F Data = Void](message String, fields F? = null) Result[Void, Error]

Logger.error#

Logs at Error when enabled. This records a failure for diagnosis; it does not raise a fault. Fields are encoded as in log.

Manuscript
fn error[F Data = Void](message String, fields F? = null) Result[Void, Error]

Logger.fatal#

Logs at Fatal when enabled. Logging does not stop the process; the caller must do that. Fields are encoded as in log.

Manuscript
fn fatal[F Data = Void](message String, fields F? = null) Result[Void, Error]

Logger.flush#

Flushes the logger’s transport.

Manuscript
fn flush() Result[Void, Error]

Logger.info#

Logs at Info when enabled. Ordinary operational records. Fields are encoded as in log.

Manuscript
fn info[F Data = Void](message String, fields F? = null) Result[Void, Error]

Logger.is_enabled#

Tests whether records at level pass the threshold; Silent is never enabled.

Manuscript
fn is_enabled(level LogLevel) Bool

Logger.level#

Returns this logger’s current threshold, independent of its parent or children.

Manuscript
fn level() LogLevel

Logger.log#

Writes a record at the selected level. fields is any Data value stringify accepts.

The value is written as is under the record’s data key, so a record, map, list, or number keeps its shape. No fields, or null, write the message alone. A value that cannot be encoded, such as a cyclic one, returns EBADMSG; encoding happens only when the level is enabled. The fields of child loggers are written under context. Silent is a threshold, not a record level, and returns EINVAL.

Manuscript
fn log[F Data = Void](level LogLevel, message String, fields F? = null) Result[Void, Error]

Logger.set_level#

Changes only this logger’s threshold; existing child loggers keep the threshold they copied.

Manuscript
var fn set_level(level LogLevel) Void

Logger.trace#

Logs at Trace, the most detailed level, when enabled. A filtered call returns ok without encoding the fields or touching the transport. Fields are encoded as in log.

Manuscript
fn trace[F Data = Void](message String, fields F? = null) Result[Void, Error]

Logger.warn#

Logs at Warn when enabled. Returns encoding, size-limit and transport errors unchanged. Fields are encoded as in log.

Manuscript
fn warn[F Data = Void](message String, fields F? = null) Result[Void, Error]

LoggerOptions Type#

Settings for create: the minimum level (default Info), whether records carry a timestamp (default true), and an optional per-record byte limit.

Manuscript
type LoggerOptions {
    level LogLevel = LogLevel.Info
    timestamp Bool = true
    max_bytes Int? = null
}

LoggerOptions.level#

Records below this level are dropped.

Manuscript
level LogLevel = LogLevel.Info

LoggerOptions.max_bytes#

Maximum encoded bytes of one record; null adds no limit.

Manuscript
max_bytes Int? = null

LoggerOptions.timestamp#

True adds a timestamp to every record.

Manuscript
timestamp Bool = true

Transport Interface#

A destination that accepts encoded log records and can be flushed and closed.

Manuscript
interface Transport {
    fn write(data String) Result[Void, Error]
    fn write_bytes(data Bytes) Result[Void, Error]
    fn flush() Result[Void, Error]
    fn duplicate() Result[Transport, Error]
    move fn close() Void
}

Transport.close#

Releases owned resources. Later writes return EBADF.

Manuscript
move fn close() Void

Transport.duplicate#

Returns a new transport onto the same destination with its own handle. Each child logger writes through one.

Manuscript
fn duplicate() Result[Transport, Error]

Transport.flush#

Flushes the destination; what that guarantees depends on the destination.

Manuscript
fn flush() Result[Void, Error]

Transport.write#

Accepts one encoded record as text and may return the original I/O cause. An error can follow a partial write to the destination, which is not rolled back. Each logger owns its transport (see duplicate), so an implementation needs no locking.

Manuscript
fn write(data String) Result[Void, Error]

Transport.write_bytes#

Accepts one encoded record as bytes, with the same rules as write.

Manuscript
fn write_bytes(data Bytes) Result[Void, Error]

create Function#

Creates a logger that owns transport, with the level, timestamp and record-size settings in options.

Manuscript
fn create(move transport Transport, options LoggerOptions = LoggerOptions()) Result[Logger, Error] { ... }

file_transport Function#

Appends log records to a file at path.

Manuscript
fn file_transport(path String) Result[Transport, Error] { ... }

handle_transport Function#

Appends log records to an open file. The transport owns file; closing the transport closes it.

Manuscript
fn handle_transport(move file FileHandle) Transport { ... }

rotating_file_transport Function#

Appends log records to the file at path and rotates it by size. When a record would take the file past max_bytes, the file is renamed to path.1, an older path.1 to path.2, and so on up to path.<keep>; the oldest is deleted. max_bytes must be positive, and a single record larger than it is still written whole, to a fresh file. keep is the number of rotated files to retain, zero or more; zero discards the old contents. A non-positive max_bytes or a negative keep returns EINVAL. An existing file is appended to, and its current size counts toward max_bytes. Example: create(rotating_file_transport("app.log", max_bytes: 1048576, keep: 5)).

Manuscript
fn rotating_file_transport(path String, max_bytes Int, keep Int) Result[Transport, Error] { ... }

stdout_transport Function#

Writes log records to the process standard-output stream.

Manuscript
fn stdout_transport() Transport { ... }