logging

Leveled logging with [LEVEL]-prefixed lines. info and debug go to stdout; warn, error, and fatal go to stderr. Import it with import logging.

Functions

FunctionSignatureDescription
debuglogging.debug(msg?: any) → voidLog [DEBUG] to stdout, but only when debug is enabled
infologging.info(msg?: any) → voidLog [INFO] to stdout
warnlogging.warn(msg?: any) → voidLog [WARN] to stderr
errorlogging.error(msg?: any) → voidLog [ERROR] to stderr
fatallogging.fatal(msg?: any) → voidLog [FATAL] to stderr, then exit with code 1
setDebuglogging.setDebug(enabled: bool) → voidEnable or disable debug output
isDebuglogging.isDebug() → boolWhether debug output is enabled
withPrefixlogging.withPrefix(prefix: string, msg: any) → voidLog [<prefix>] <msg> to stdout

Debug output is off by default; enable it with logging.setDebug(true) or the --debug CLI flag.

Example

import logging

logging.info("server starting")

logging.setDebug(true)
logging.debug("config loaded")        // [DEBUG] config loaded

logging.withPrefix("db", "connected") // [db] connected
logging.warn("retrying connection")

if !logging.isDebug() {
  logging.error("debug should be on")
}

// logging.fatal("unrecoverable")     // prints [FATAL] and exits
Standard library · View as Markdown · llms-full.txt