Skip to content

Log Module

The std/log module provides structured, leveled logging with timestamps. Log output follows the format [timestamp] LEVEL: message context.

import { log } from "std/log"

Levels are ordered by severity. Setting a level silences all levels below it.

LevelPriorityDescription
debug0Verbose debug output
info1General information
warn2Warning conditions
error3Error conditions

The default level is info, which means debug messages are not printed.

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.1

log.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=42

Set the minimum log level. Accepts "debug", "info", "warn", or "error".

log.setLevel("warn") // Only warn and error messages will be printed
log.info("This will be silenced")
log.warn("This will print")
FunctionDescription
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

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)