@digta/logger
v0.1.0
Published
Tiny zero-dependency logger: colors, timestamps, file output, log rotation, JSON mode, production mode.
Maintainers
Readme
@digta/logger
Tiny zero-dependency logger for Node. Colors, timestamps, file output, log rotation, JSON mode, production mode. One file, no build step.
npm install @digta/loggerUsage
import logger from "@digta/logger";
// or: const logger = require("@digta/logger");
logger.info("Server Started");
logger.success("PLC Connected");
logger.warn("Heartbeat Missing");
logger.error(err); // pass an Error, its stack is printed
logger.debug("hidden by default");[09:31:20] INFO Server Started
[09:31:22] SUCCESS PLC Connected
[09:31:24] WARNING Heartbeat Missing
[09:31:30] ERROR Socket Hangupwarn and error go to stderr, everything else to stdout. Colors turn off automatically when the output isn't a terminal (piped or redirected).
Custom logger
import { createLogger } from "@digta/logger";
const logger = createLogger({
level: "debug", // debug | info | success | warn | error | silent
file: "./logs/app.log", // also append to a file
maxSize: 5 * 1024 * 1024, // rotate at 5 MB (0 = never)
maxFiles: 3, // keep app.log.1 … app.log.3
json: false, // newline-delimited JSON
color: true,
timestamp: true,
});Production / JSON mode
With NODE_ENV=production (or production: true), output defaults to line-delimited JSON with color off — ready to pipe into any log collector:
{"time":"2026-07-19T16:42:39.975Z","level":"info","msg":"server up"}Options
| Option | Default | What it does |
|--------------|--------------------------------|-----------------------------------------------|
| level | "info" | Minimum level to emit; "silent" mutes all |
| json | on in production | Newline-delimited JSON instead of pretty text |
| color | on for TTY, non-prod, non-json | ANSI colors |
| file | null | Path to also append logs to |
| maxSize | 5 MB | Rotate file at this size; 0 disables |
| maxFiles | 3 | Rotated backups to keep |
| timestamp | true | Prefix each line with [HH:MM:SS] |
| production | NODE_ENV === "production" | Forces json on, color off |
License
MIT
