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#
pub enum LogLevelThe level of a log message, from Trace (most detail) to Error (most serious).
Trace#
TraceVery detailed messages to trace a problem.
Debug#
DebugMessages that help during development.
Info#
InfoNormal events in the operation of the program.
Warning#
WarningA problem that the program recovered from.
Error#
ErrorAn operation that did not complete as intended.
Logger#
pub ambient service Logger default WarningsToStderrReceives structured log events from any running code through a shared provider.
WarningsToStderr#
pub struct WarningsToStderrEmits warnings and errors to stderr on native and WASI targets, or to the web console.
Implementation Logger for WarningsToStderr#
impl Logger for WarningsToStderrOperation log#
effect fn log<Args>(self: &Self, level: LogLevel, static template: string<'static>, args: &Args) -> ()Implementation Logger#
impl LoggerAssociated function inMemoryProvider#
pub effect fn inMemoryProvider() -> InMemoryLogger ! OutOfMemoryError ? &mut AllocatorCreates 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#
pub effect fn inMemoryProviderFailAt(failAt: usize) -> InMemoryLogger ! OutOfMemoryError ? &mut AllocatorCreates 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#
pub fn length(self: &InMemoryLogger) -> usizeReturns 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#
pub fn levelAt(self: &InMemoryLogger, index: usize) -> LogLevelReturns 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#
pub fn messageLengthAt(self: &InMemoryLogger, index: usize) -> usizeReturns 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#
pub fn messageByteAt(
self: &InMemoryLogger,
eventIndex: usize,
byteIndex: usize
) -> u8Returns 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#
pub fn attempts(self: &InMemoryLogger) -> usizeReturns the number of calls attempted, including discarded events.
InMemoryLogger#
pub struct InMemoryLoggerA 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#
impl Logger for InMemoryLoggerOperation log#
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.