Features
Familiar methods
Wraps log, info, warn, error and debug. Everything else on the console is left untouched.
Node.js and browser
ANSI escape codes in the terminal, %c CSS in DevTools. One API for both.
Per-method defaults
configure() sets a default style for each method and merges on repeated calls.
Non-mutating style()
style() returns a new logger with overrides. The original is never changed, and calls chain.
Usage
Use a local logger, or patch the global console.
Local logger
Import the logger without touching the global console.
app.js
import logger from "styling-console/logger";
logger.configure({
log: { bold: true, color: "green" },
error: { bold: true, color: "red" },
});
logger.log("Build complete");
logger.style({ italic: true, color: "blue" }).log("One-off line");Global console
Importing the package patches console. restore() undoes it, install() re-applies it.
app.js
import { restore } from "styling-console";
console.configure({ error: { bold: true, color: "red" } });
console.error("Something went wrong");
console.style({ background: "cyan", color: "black" }).log("Highlighted");
restore(); // back to the original consoleTry it
Pick a style and see the output and the code that produces it.
output
logHello from styling-console
app.js
import logger from "styling-console/logger";
logger.style({ bold: true, color: "cyan" }).log("Hello from styling-console");Supported styles
Every colour works as a foreground (color) and a background.
bold italic
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
Node.js and browser
Node.js
- Styles use ANSI escape codes.
- Colours only appear when the stream is a TTY.
FORCE_COLORforces colours on;0orfalseforces them off.NO_COLORdisables colours.
Browser
- Styles use
%cand CSS in DevTools. - No separate API or build step needed.
- Works with any bundler that supports ESM.
Notes
- Only string arguments are styled; other values pass through unchanged.
style()never changes existing configuration.- Passing
nullfor a method inconfigure()resets it. - An unknown colour throws a
TypeError. - Meant for developer-tool output, not HTML or DOM styling.