silk.io.logger.

Libraries log through the ambient Logger. A plain function can run Effect.logWarning without adding a requirement or failure to its signature. Programs choose where observations go. WarningsToStderr emits warnings and errors when the program uses the default.

Import as Logger with import silk.io.logger { Logger }.

Public declarations: 4.

LogLevel#

silk
pub enum LogLevel

The level of a log message, from Trace (most detail) to Error (most serious).

Trace#

silk
Trace

Very detailed messages to trace a problem.

Debug#

silk
Debug

Messages that help during development.

Info#

silk
Info

Normal events in the operation of the program.

Warning#

silk
Warning

A problem that the program recovered from.

Error#

silk
Error

An operation that did not complete as intended.

Logger#

silk
pub ambient service Logger default WarningsToStderr

Receives structured log events from any running code through a shared provider.

WarningsToStderr#

silk
pub struct WarningsToStderr

Emits warnings and errors to stderr on native and WASI targets, or to the web console.

Implementation Logger for WarningsToStderr#

silk
impl Logger for WarningsToStderr

Operation log#

silk
effect fn log<Args>(self: &Self, level: LogLevel, static template: string<'static>, args: &Args) -> ()

Implementation Logger#

silk
impl Logger

Associated function inMemoryProvider#

silk
pub effect fn inMemoryProvider() -> InMemoryLogger ! OutOfMemoryError ? &mut Allocator

Creates an empty in-memory logger with capacity for eight events and 64 message bytes.

Gotchas#

The logger drops the entire event when eight events are already committed or the formatted message exceeds the remaining byte capacity. The attempt still counts.

Associated function inMemoryProviderFailAt#

silk
pub effect fn inMemoryProviderFailAt(failAt: usize) -> InMemoryLogger ! OutOfMemoryError ? &mut Allocator

Creates an in-memory logger that rejects one zero-based attempted-call ordinal.

Details#

The configured attempt increases attempts but does not increase length or consume message capacity. Other attempts retain the eight-event and 64-byte limits of inMemoryProvider.

Method length#

silk
pub fn length(self: &InMemoryLogger) -> usize

Returns the number of events that the in-memory logger committed.

Details#

Failed attempts do not increase this count. Use Logger.attempts when rejected calls must also be observed.

Method levelAt#

silk
pub fn levelAt(self: &InMemoryLogger, index: usize) -> LogLevel

Returns the severity of one committed event.

Gotchas#

index must be less than length. An unused index below eight returns the initial Trace value instead of trapping. An index of eight or more traps.

Method messageLengthAt#

silk
pub fn messageLengthAt(self: &InMemoryLogger, index: usize) -> usize

Returns the UTF-8 byte length of one committed message.

Gotchas#

index must be less than length. An unused index below eight returns zero instead of trapping. An index of eight or more traps.

Method messageByteAt#

silk
pub fn messageByteAt(
    self: &InMemoryLogger,
    eventIndex: usize,
    byteIndex: usize
  ) -> u8

Returns one UTF-8 byte from a committed message.

Gotchas#

eventIndex must be less than length. byteIndex must be less than messageLengthAt for that event. An unused event or invalid byte index traps. An event index of eight or more also traps.

Method attempts#

silk
pub fn attempts(self: &InMemoryLogger) -> usize

Returns the number of calls attempted, including discarded events.

InMemoryLogger#

silk
pub struct InMemoryLogger

A deterministic Logger provider that retains up to eight events and 64 total message bytes.

When to use#

Use this provider in tests that must inspect event order, severity, message bytes, or failure behavior without process output.

Details#

The provider copies each committed message into fixed internal storage. It records attempted calls separately from committed events. Capacity failure and configured failure do not commit an event.

Gotchas#

The accessors need an event index less than Logger.length and a byte index less than the message length.

Implementation Logger for InMemoryLogger#

silk
impl Logger for InMemoryLogger

Operation log#

silk
effect fn log<Args>(self: &Self, level: LogLevel, static template: string<'static>, args: &Args) -> ()

Category: Input and output.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page