AnsiLogger is a lightweight, customizable color logger for Node.js.
If you like this project and find it useful, please consider giving it a star on GitHub and sponsoring it.
- Simple and intuitive API for data logging.
- No dependencies.
- Customizable colors and apperance.
- Supports environment variable NO_COLOR=1 (https://no-color.org/).
- It is also possible to pass a top level logger (like Homebridge or Matter logger) and AnsiLogger will use it for output instead of console.
- Includes also a fully customizable stringify funtion with colors (it is bigint aware and manage circular reference).
- Includes a chainable ANSI tagged template API (
ansi) for styling terminal strings directly.
- Node.js 20-22-24 installed on your machine.
To get started with AnsiLogger in your package
npm install node-ansi-loggerCreate an instance of AnsiLogger.
import { AnsiLogger, AnsiLoggerParams, LogLevel } from 'node-ansi-logger';const log = new AnsiLogger({ logName: '<your name>' }); // Eventually other params in AnsiLoggerParamsTo import the stringify functions
import { stringify, payloadStringify, colorStringify, mqttStringify, debugStringify } from 'node-ansi-logger';log.debug('Debug message...', ...parameters);
log.info('Info message...', ...parameters);
log.notice('Notice message...', ...parameters);
log.warn('Warning message', ...parameters);
log.error('Error message', ...parameters);
log.fatal('Fatal message', ...parameters);
log(LogLevel.WARN, 'Warning message', ...parameters);log.debug(`Debug message ${YELLOW}with yellow part${db}`, ...);log.startTimer('Time sensitive code started');
log.stopTimer('Time sensitive code finished');stringify({...})
colorStringify({...})Import the ansi root tag or individual named styles:
import { bold, red, green, cyan, bgBlue, warn, error, fatal, hex, rgb, bgHex, bgRgb } from 'node-ansi-logger';Apply a single style:
console.log(red`Something went wrong`);
console.log(bold`Important message`);Chain multiple styles:
console.log(bold.red`Critical error`);
console.log(bgBlue.green`Green on blue`);
console.log(bold.italic.underline`Decorated text`);Use dynamic RGB or hex colors:
console.log(rgb(255, 128, 0)`Orange text`);
console.log(hex('#ff75d1').bold`Pink bold`);
console.log(bgRgb(30, 30, 30).cyan`Cyan on dark background`);
console.log(bgHex('#1a1a2e').white`White on dark blue`);Nest styles — outer styles are automatically restored after inner resets:
console.log(green`Connected ${bold.red`FAILED`} retrying...`);
console.log(warn`Server ${error.bold`crashed`} restarting`);Use the 24-step grayscale ramp (gray0 = darkest, gray23 = lightest):
import { gray0, gray8, gray13, gray20, gray23 } from 'node-ansi-logger';
console.log(gray0`Nearly black`);
console.log(gray8`Dark gray`);
console.log(gray13`Mid gray`);
console.log(gray20`Light gray`);
console.log(gray23`Nearly white`);Log-level color exports:
import { success, debug, info, notice, warn, error, fatal } from 'node-ansi-logger';
console.log(success`Operation completed`);
console.log(debug`Debug details`);
console.log(fatal`Unrecoverable error`);Mix ansi styles inside AnsiLogger calls:
import { AnsiLogger } from 'node-ansi-logger';
import { bold, red, green, cyan, yellow } from 'node-ansi-logger';
const log = new AnsiLogger({ logName: 'MyApp' });
log.info(`Device ${bold.cyan`Kitchen Light`} connected`);
log.warn(`Retry ${yellow`${3}`} of ${yellow`5`} — response timeout`);
log.error(`Failed to reach ${bold`192.168.1.10`}: ${red`connection refused`}`);
log.debug(`State changed: ${green`on`} → ${red`off`}`);Note: This repository uses a new toolchain. It replaces the traditional TypeScript / ESLint / Prettier / Jest stack with a faster and lighter setup.
- No
typescript 6.xpackage — replaced by TypeScript Native 7.x. - No ESLint, no Prettier — replaced by the oxc stack: oxlint for linting and oxfmt for formatting.
- No Jest — replaced by Vitest, which is much faster and natively supports ESM without extra configuration.
- Far fewer development dependencies — the number of installed packages drops from ~600 to ~75. A clean install is much faster.
- Much faster linting and formatting — oxlint and oxfmt run in a fraction of the time required by the ESLint / Prettier pipeline.
- Much faster builds — tsgo compiles the project in a fraction of the time required by the standard
tscbuild. - Editor support — use the VS Code extensions for tsgo and oxc to get the same experience in the editor.
All coding agents read the same guidance. AGENTS.md and .agents/ are the single source of truth; everything under .github/, .claude/, .codex/ and .antigravity/ are pointers and mirrors. Edit .agents/ (or AGENTS.md), never the copies. See .agents/README.md for the full layout.
| File | Notes |
|---|---|
AGENTS.md |
Main project instructions — shared by every agent |
.agents/README.md |
Layout and versioning of the shared instructions |
.agents/rules/testing.instructions.md |
Testing standards for unit tests |
.agents/skills/verify-agent-context/SKILL.md |
Verify the agent loaded this context — $verify-agent-context (Codex), /verify-agent-context (all others) |
Content lives only in .agents/. The per-agent folders exist because each tool discovers rules and skills from its own hardcoded location, so they hold stubs that point back here — except where the tool reads .agents/ natively.
| Tool | Instructions | Rules | Skills |
|---|---|---|---|
| Codex | AGENTS.md — read natively |
.agents/rules/ — linked from AGENTS.md, on demand |
.agents/skills/ — native, $verify-agent-context |
| Copilot (VS Code and coding agent) | .github/copilot-instructions.md → AGENTS.md |
stubs in .github/instructions/ — applyTo globs |
stub in .github/skills/ — /verify-agent-context |
| Claude Code | CLAUDE.md imports AGENTS.md |
stubs in .claude/rules/ — paths globs |
stub in .claude/skills/ — /verify-agent-context |
| Gemini / Antigravity | GEMINI.md imports AGENTS.md |
.agents/rules/ — on demand |
.agents/skills/ — native, /verify-agent-context |
| File | Notes |
|---|---|
.github/copilot-instructions.md |
Pointer to AGENTS.md — always loaded |
.github/instructions/testing/testing.instructions.md |
Testing standards — scoped to **/*.test.ts |
.github/skills/verify-agent-context/SKILL.md |
Skill invocable as /verify-agent-context |
| File | Notes |
|---|---|
CLAUDE.md |
Pointer to AGENTS.md — always loaded |
.claude/settings.json |
Claude permissions: allow, ask and deny rules |
.claude/rules/testing/testing.instructions.md |
Testing standards — scoped to **/*.test.ts |
.claude/skills/verify-agent-context/SKILL.md |
Skill invocable as /verify-agent-context |
| File | Notes |
|---|---|
AGENTS.md |
Main project instructions — read directly, no pointer file needed |
.codex/config.toml |
Codex project permissions, approvals, and profile |
.codex/rules/default.rules |
Codex command allow, prompt, and deny rules |
Codex reads the shared rules and skills from .agents/ directly; the skill is invoked as $verify-agent-context.
| File | Notes |
|---|---|
GEMINI.md |
Pointer to AGENTS.md — always loaded |
.antigravity/settings.json |
Sandboxing and permissions: allow, ask and deny rules |
The shared rules under .agents/rules/ apply on demand for the relevant tasks, and .agents/skills/ is discovered automatically as /verify-agent-context.
Contributions to AnsiLogger are welcome.
This project is licensed under the MIT License - see the LICENSE file for details.