Log Module
The std/log module provides structured, leveled logging with timestamps. Log output follows the format [timestamp] LEVEL: message context.
Import
Section titled “Import”import { log } from "std/log"Log Levels
Section titled “Log Levels”Levels are ordered by severity. Setting a level silences all levels below it.
| Level | Priority | Description |
|---|---|---|
debug | 0 | Verbose debug output |
info | 1 | General information |
warn | 2 | Warning conditions |
error | 3 | Error conditions |
The default level is info, which means debug messages are not printed.
Functions
Section titled “Functions”log.info(message: string, context?: any): void
Section titled “log.info(message: string, context?: any): void”Log an informational message.
log.info("Server started")// [2026-01-15 14:30:00] INFO: Server started
log.info("User logged in", { "userId": "123", "ip": "10.0.0.1" })// [2026-01-15 14:30:00] INFO: User logged in userId=123 ip=10.0.0.1log.warn(message: string, context?: any): void
Section titled “log.warn(message: string, context?: any): void”Log a warning message.
log.warn("Disk usage high", { "usage": "92%" })// [2026-01-15 14:30:00] WARN: Disk usage high usage=92%log.error(message: string, context?: any): void
Section titled “log.error(message: string, context?: any): void”Log an error message. Context can be an Error object, a map, or a string.
log.error("Request failed", { "status": "500", "path": "/api/data" })// [2026-01-15 14:30:00] ERROR: Request failed status=500 path=/api/data
try { // ... risky operation} catch (err) { log.error("Operation failed", err) // [2026-01-15 14:30:00] ERROR: Operation failed error=something went wrong}log.debug(message: string, context?: any): void
Section titled “log.debug(message: string, context?: any): void”Log a debug message. Only printed when the log level is set to "debug".
log.setLevel("debug")log.debug("Processing item", { "id": "42" })// [2026-01-15 14:30:00] DEBUG: Processing item id=42log.setLevel(level: string): void
Section titled “log.setLevel(level: string): void”Set the minimum log level. Accepts "debug", "info", "warn", or "error".
log.setLevel("warn") // Only warn and error messages will be printedlog.info("This will be silenced")log.warn("This will print")Function Reference
Section titled “Function Reference”| Function | Description |
|---|---|
log.info(message, context?) | Log an info-level message |
log.warn(message, context?) | Log a warning-level message |
log.error(message, context?) | Log an error-level message |
log.debug(message, context?) | Log a debug-level message |
log.setLevel(level) | Set minimum log level |
Example: HTTP Server Logging
Section titled “Example: HTTP Server Logging”The HTTP server has built-in request logging enabled by default. You can also use the log module in your handlers for application-level logging:
import { createServer, Request, Response } from "std/http"import { log } from "std/log"
log.setLevel("debug")
const app = createServer()
app.get("/users/:id", function(req: Request, res: Response): Response { log.debug("Fetching user", { "id": req.params.id }) return res.json('{"id": "' + req.params.id + '"}')})
app.listen(3000)