Module std::misc::log

Structured logging for Hew programs.

import std::misc::log; Provides five log levels with structured key-value fields and automatic actor context injection.

Usage

fn main() {
    log.setup();
    log.info("server starting", port: 8080);
    log.debug("cache initialized", capacity: 1024);
}

Levels

ERROR (0) > WARN (1) > INFO (2) > DEBUG (3) > TRACE (4)

Output

Default: coloured text to stderr

12:34:56.789 INFO  server starting  port=8080

Contents

Functions

Function setup

pub fn setup()

Initialize logging at the default INFO level.

Function setup_level

pub fn setup_level(level: i32)

Initialize logging at a specific level.

Levels: 0=error, 1=warn, 2=info, 3=debug, 4=trace.

Examples

log.setup_level(3); // enable debug and above

Function set_level

pub fn set_level(level: i32)

Set the log level filter.

Function get_level

pub fn get_level() -> i32

Get the current log level filter.

Function set_format

pub fn set_format(format: i32)

Set the log output format.

Use log.TEXT (0) for coloured text or log.JSON (1) for NDJSON.

Examples

log.set_format(log.JSON);
log.info("structured", service: "api");

Function get_format

pub fn get_format() -> i32

Get the current log output format.

Function error

pub fn error(msg: String)

Log a message at error level (named args handled by compiler).

Function warn

pub fn warn(msg: String)

Log a message at warn level.

Function info

pub fn info(msg: String)

Log a message at info level.

Function debug

pub fn debug(msg: String)

Log a message at debug level.

Function trace

pub fn trace(msg: String)

Log a message at trace level.