log

Levelled diagnostics with stderr output and filtering.

Structured diagnostics for Dune programs.

The first stage exposes levelled human logging with process-wide filtering. Logs are written to stderr by the VM __log_emit intrinsic so normal program output on stdout stays separate. The active level defaults to info, can be set from DUNE_LOG or DUNE_LOG_LEVEL, and can be changed at runtime with set_level.

log provides a small diagnostics API for command-line tools and longer-running programs. It keeps logs on stderr, separate from regular io.println output on stdout, and filters messages below the active level.

The default level is info. Set DUNE_LOG or DUNE_LOG_LEVEL to trace, debug, info, warn, error, or off, or call log.set_level from Dune code.

import log;

log.set_level(log.DEBUG);
log.info("building target");
log.warn("using fallback config");

Auto-generated from stdlib/log.dn by tools/gen_stdlib_docs.py.

const TRACE: int

The most verbose level.

Example:

log.set_level(log.TRACE)

const DEBUG: int

Debug-level diagnostics.

const INFO: int

Informational diagnostics; this is the default active level.

const WARN: int

Warnings for recoverable problems.

const ERROR: int

Errors for failed operations that the program can still report.

const OFF: int

Disable all log output.

fn set_level(level: int): unit

Set the active minimum level. Messages below this level are suppressed.

Example:

log.set_level(log.WARN)

fn level(): int

Return the active minimum level (INFO = 2 by default).

Example:

log.level()  // 2

fn enabled(level: int): bool

True when a message at level would be emitted at the active level.

Example:

log.enabled(log.ERROR)  // 1

fn trace(message: text): unit

Emit a trace message (suppressed unless the level is lowered to TRACE).

Example:

log.set_level(log.TRACE); log.trace("parsing input")  // stderr: [trace] parsing input

fn debug(message: text): unit

Emit a debug message (suppressed unless the level is lowered to DEBUG).

Example:

log.set_level(log.DEBUG); log.debug("cache miss")  // stderr: [debug] cache miss

fn info(message: text): unit

Emit an informational message (shown at the default level).

Example:

log.info("building target")  // stderr: [info] building target

fn warn(message: text): unit

Emit a warning message.

Example:

log.warn("using fallback config")  // stderr: [warn] using fallback config

fn error(message: text): unit

Emit an error message.

Example:

log.error("connection refused")  // stderr: [error] connection refused