logger-chroma
v1.0.9
Published
π¦ A colorful, developer-friendly Node.js logger with timestamps, emojis, pretty-printed objects, and grouped logs for clear, readable output.
Maintainers
Readme
logger-chroma
- π¨ A lightweight, high-performance Node.js logging utility designed for developers who need to visualize complex, nested operations.
logger-chromatransforms flat, messy console outputs into a beautiful, structured tree that makes debugging logical flows intuitive. - π¨βπ» Optimized for modern terminals like
Windows Terminal,VS Code Integrated Terminal,iTerm2, andWindows Git Bash Terminalwhere box-drawing characters are rendered natively. - β»οΈ Works seamlessly with
CommonJS,ESMandTypeScript
π¦ Install via NPM
$ npm i logger-chromaπ» Usage
- See examples below
ESM (Random example)
import loggerChroma from 'logger-chroma';
// --| Server start
loggerChroma.info("Server starting on port", 3000, "π");
// --| Environment info
loggerChroma.debug({ env: process.env.NODE_ENV || "development", version: "1.0.0" }, "π‘", "Current environment");
// --| Full HTTP request handling example
loggerChroma.group("HTTP GET /users", () => {
loggerChroma.info("Request received", "π₯");
// --| Authentication
loggerChroma.group("Auth check", () => {
const user = { id: 1, role: "admin", permissions: ["read", "write"] };
loggerChroma.debug(user, "π΅οΈ", "User payload");
loggerChroma.group("Token validation", () => {
const token = { valid: true, expires: "2026-03-05T18:00:00Z" };
loggerChroma.debug(token, "π", "Token info");
loggerChroma.info("Token is valid", "β
");
});
loggerChroma.info("Authentication passed", "β
");
});
// --| Database query
loggerChroma.group("DB query", () => {
const users = [
{ id: 1, name: "Alice", active: true },
{ id: 2, name: "Bob", active: false },
{ id: 3, name: "Charlie", active: true },
];
loggerChroma.debug(users, "ποΈ", "Fetched users");
loggerChroma.group("Filter active users", () => {
const activeUsers = users.filter(u => u.active);
loggerChroma.info(activeUsers, "π", "Active users list");
});
});
loggerChroma.info("Request completed", "π―");
});
// --| Another route example
loggerChroma.group("HTTP POST /orders", () => {
loggerChroma.info("Request received", "π₯");
loggerChroma.group("Auth check", () => {
const user = { id: 2, role: "customer" };
loggerChroma.debug(user, "π΅οΈ", "User payload");
loggerChroma.info("Authentication passed", "β
");
});
loggerChroma.group("DB insert order", () => {
const order = { id: 101, items: ["apple", "banana"], total: 12.5 };
loggerChroma.debug(order, "π", "Order object");
loggerChroma.group("Send notification", () => {
const notification = { to: "[email protected]", status: "sent" };
loggerChroma.info(notification, "π§", "Notification sent");
});
});
loggerChroma.info("Order processed successfully", "π―");
});
// --| Error example
try {
throw new Error("Something went horribly wrong!");
} catch (err) {
loggerChroma.error(err, "π¦", "Critical error during request handling");
}
// --| Final server ready message
loggerChroma.info("Server ready to accept requests", "β¨");CommonJS (Random example)
const loggerChroma = require('logger-chroma');
loggerChroma.info('Server started successfully');
loggerChroma.warn('Low disk space', 'β οΈ');
loggerChroma.error('Failed to connect to database', new Error('Connection Timeout'));
// --| Logging objects (automatically pretty-printed via util.inspect)
const user = { id: 1, name: 'Gemini', roles: ['admin', 'ai'] };
loggerChroma.debug('Current user context:', user);
// --| Using the grouping feature
loggerChroma.group('Initialize Module', () => {
loggerChroma.info('Loading configuration...');
// --| Nested Group
loggerChroma.group('Database Check', () => {
loggerChroma.info('Connecting to PostgreSQL...', 'π');
loggerChroma.info('Connection established.');
});
loggerChroma.info('Module ready.');
});
// --| Overriding config on the fly
loggerChroma.config.timestampEnabled = false;
loggerChroma.info('This log has no timestamp');TypeScript (Random example)
import loggerChroma from 'logger-chroma';
loggerChroma.info('Server started successfully');
loggerChroma.warn('Low disk space', 'β οΈ');
loggerChroma.error('Failed to connect to database', new Error('Connection Timeout'));
interface User {
id: number;
name: string;
roles: string[];
}
const user: User = { id: 1, name: 'Gemini', roles: ['admin', 'ai'] };
loggerChroma.debug('Current user context:', user);
loggerChroma.group('Initialize Module', () => {
loggerChroma.info('Loading configuration...');
// --| Nested Grouping
loggerChroma.group('Database Check', () => {
loggerChroma.info('Connecting to PostgreSQL...', 'π');
loggerChroma.info('Connection established.');
});
loggerChroma.info('Module ready.');
});
if (loggerChroma.config) {
loggerChroma.config.timestampEnabled = false;
loggerChroma.info('This log has no timestamp');
}