Djinn Lang
Std

Logger

Overview

The Logger struct in std::logger provides structured logging with multiple severity levels. Backed by a C runtime logger implementation.

import std::logger;

Log Levels

Level

Enum Value

Description

TRACE0Fine-grained diagnostic information
DEBUG1Debugging information
INFO2Informational messages
WARN3Potentially harmful situations
ERROR4Error events
FATAL5Critical errors that may cause termination

Output Targets

enum LoggerOutput {
    STDOUT,
    STDERR
}

Constructor

Logger log = Logger("my-service");

Creates a logger with the given name, defaulting to stdout and TRACE level.

Methods

Method

Description

trace(str message)Log at TRACE level
debug(str message)Log at DEBUG level
info(str message)Log at INFO level
warn(str message)Log at WARN level
error(str message)Log at ERROR level
fatal(str message)Log at FATAL level
setLevel(i32 level)Change the minimum log level
destroy()Frees the logger resources

Example

import std::logger;

void main() {
    Logger log = Logger("app");

    log.info("Application started");
    log.debug("Loading configuration...");
    log.warn("Config file not found, using defaults");
    log.error("Failed to connect to database");

    log.destroy();
}

On this page