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 informationDEBUG1Debugging informationINFO2Informational messagesWARN3Potentially harmful situationsERROR4Error eventsFATAL5Critical errors that may cause terminationOutput 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 leveldebug(str message)Log at DEBUG levelinfo(str message)Log at INFO levelwarn(str message)Log at WARN levelerror(str message)Log at ERROR levelfatal(str message)Log at FATAL levelsetLevel(i32 level)Change the minimum log leveldestroy()Frees the logger resourcesExample
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();
}