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
| Function | Signature | Description |
|---|---|---|
debug | logging.debug(msg?: any) → void | Log [DEBUG] to stdout, but only when debug is enabled |
info | logging.info(msg?: any) → void | Log [INFO] to stdout |
warn | logging.warn(msg?: any) → void | Log [WARN] to stderr |
error | logging.error(msg?: any) → void | Log [ERROR] to stderr |
fatal | logging.fatal(msg?: any) → void | Log [FATAL] to stderr, then exit with code 1 |
setDebug | logging.setDebug(enabled: bool) → void | Enable or disable debug output |
isDebug | logging.isDebug() → bool | Whether debug output is enabled |
withPrefix | logging.withPrefix(prefix: string, msg: any) → void | Log [<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