chalk-ts-logger
v6.2.5
Published
Console log with a text parameter
Downloads
444
Readme
chalk-ts-logger
Structured console logging for Node with levels, timestamps, namespaces, and helpers for aligned log lines.
Install
npm install chalk-ts-loggerBuild from source: npm install then npm run build (outputs to dist/).
Quick start
import {
logText,
logInfo,
logWarn,
logError,
createLogger,
} from "chalk-ts-logger";
logInfo("Server listening");
logWarn("Deprecated option used");
logError("Connection failed");
logText("Plain line (no level tag)");Logger API
Default logger
logText(text)— prints a line without a level tag (still respectssilentand namespace).logInfo,logWarn,logError,logDebug,logTrace— convenience wrappers on the package default logger.getDefaultLogger()/setDefaultLogger(instance)— access or replace the singleton.resetDefaultLogger(options?)— new default instance with optional options.withDefaultLogger(instance, fn)— runfnwith a temporary default, then restore the previous one.
ChalkTsLogger
Create isolated loggers with createLogger(options?, writer?) or new ChalkTsLogger(options?, writer?).
LoggerOptions
| Option | Description |
|--------|-------------|
| level | Minimum level: silent | error | warn | info | debug | trace (default info). silent disables output. |
| namespace | Prefix segment after the level tag, e.g. [myapp:api]. |
| timestamps | Prefix each line with a local timestamp (default true). |
| locale | Passed to toLocaleString when timestamps are on. |
| sanitize | Escape control characters in message bodies. |
| levelTagWidth | Fixed width for the level column in [LEVEL]. |
Methods: trace, debug, info, warn, error, logText, and child(segment) for a nested namespace.
LogWriter: optional { log(line), error(line) } to redirect output (defaults to console.log / console.error). Errors use the error writer.
Format helpers
Exported from the same package for custom layouts:
formatTimestamp, formatLevelTag, prefixLines, padText, formatBanner, formatRule, formatKeyValue, escapeControlChars.
License
MIT
