khanya-logger
v2.0.0
Published
Enterprise-grade logger for Node.js with async file logging, color-coded console, JSON output, and rotation.
Maintainers
Readme
khanya-logger Enterprise
Full-featured, enterprise-grade logger for Node.js with:
- Color-coded console logs
- Asynchronous file logging
- Daily & size-based log rotation
- JSON output support
- Per-destination log level filtering
Features
- ✅
debug,info,warn,errorlog levels - ✅ Console & file log level filtering
- ✅ ISO timestamps
- ✅ Color-coded console output
- ✅ JSON structured logs for external aggregators
- ✅ Async file writes for high-performance
- ✅ Daily & size-based file rotation
- ✅ Lightweight and zero dependencies
Installation
npm
npm install khanya-logger
yarn
yarn add khanya-logger
pnpm
pnpm add khanya-logger
Usage
import { Logger } from "khanya-logger";
// Console sees all logs, file sees only info+ logs
const logger = new Logger({
consoleLevel: "debug",
fileLevel: "info",
file: "logs/log-{date}.txt",
json: false,
maxFileSize: 5 * 1024 * 1024 // 5MB
});
logger.debug("Debug message"); // Console only
logger.info("Info message"); // Console + File
logger.warn("Warning message"); // Console + File
logger.error("Error message"); // Console + File
// JSON file example
const jsonLogger = new Logger({
consoleLevel: "info",
fileLevel: "warn",
file: "logs/json-log-{date}.txt",
json: true,
maxFileSize: 5 * 1024 * 1024
});
jsonLogger.info("Info JSON log"); // Console only
jsonLogger.warn("Warning JSON log"); // Console + File
jsonLogger.error("Error JSON log"); // Console + File