std:log
Contents
Log
Leveled logging to stderr. The functions can also be imported one by one, e.g. import { info, warn } from "std:log".
Log Levels
| Level | Value | Description |
|---|---|---|
| TRACE | 0 | Very detailed debugging |
| DEBUG | 1 | Debug information |
| INFO | 2 | General information (default) |
| WARN | 3 | Warnings |
| ERROR | 4 | Errors |
| FATAL | 5 | Fatal errors |
| OFF | 6 | Disable all logging |
The level belongs to the script. It does not depend on RUST_LOG.
Methods
Each logging method takes any number of values and joins them with spaces.
fn trace(...args)
Log a trace-level message.
import { Log } from "std:log";
Log.setLevel("trace");
Log.trace("Entering function", "parseConfig");Runfn debug(...args)
Log a debug-level message.
import { Log } from "std:log";
let x = 42;
Log.setLevel("debug");
Log.debug("Variable value:", x);Runfn info(...args)
Log an info-level message.
fn warn(...args)
Log a warning-level message.
fn error(...args)
Log an error-level message.
fn fatal(...args)
Log a fatal-level message. It only logs; it does not stop the program.
fn setLevel(level: String | Int)
Set the minimum log level. Messages below this level are dropped. Takes a level name ("trace" to "fatal", or "off") or a number from 0 to 6.
import { Log } from "std:log";
Log.setLevel("debug"); // Show debug and above
Log.setLevel(4); // Show error and above only
Log.setLevel("off"); // Disable all loggingRunfn getLevel(): String
Get the current log level as a lowercase string.
fn create(prefix: String): Map
Create a logger that starts each message with prefix. It has the methods trace, debug, info, warn, error, and fatal, and uses the global level.
import { Log } from "std:log";
let dbLog = Log.create("[DB]");
dbLog.info("Connected to database"); // ... INFO - [DB] Connected to databaseRunExample
import { Log } from "std:log";
// Set level to debug for development
Log.setLevel("debug");
// Log different types of data
Log.info("Application started");
Log.debug("Config:", { port: 8080, debug: true });
Log.warn("Cache miss for key:", "user:123");
Log.error("Request failed:", { status: 500, message: "Internal error" });
// Create module-specific loggers
let authLog = Log.create("[Auth]");
authLog.info("User logged in:", "john@example.com");
// In production, set to warn or error
Log.setLevel("warn");RunOutput Format
Each line has the local time, the level, and the message:
[2026-02-01T01:49:11] INFO - Application started
[2026-02-01T01:49:11] DEBUG - Config: {port: 8080, debug: true}
[2026-02-01T01:49:11] WARN - Cache miss for key: user:123
[2026-02-01T01:49:11] ERROR - Request failed: {status: 500, message: Internal error}
[2026-02-01T01:49:11] INFO - [Auth] User logged in: john@example.com