@dungdv/build-log
v1.0.6
Published
Simple colored logger with optional file logging
Readme
@dungdv/build-log
Simple logger written in TypeScript that logs messages to the console (with color) and optionally to a file.
✨ Features
- 📦 Console output with color (
info,warn,error,debug) - 📝 Optional file logging
- 🚀 Written in TypeScript with type definitions
- 📊 Supports both ES Modules and CommonJS
- ✅ Compatible with Node.js v22.x and later
📦 Installation
npm install @dungdv/build-log🚀 Usage
ES Modules (import)
import { buildLog } from "@dungdv/build-log";
// Basic usage with info level (green)
buildLog({
levelLog: "info",
messageLog: "Server started successfully!",
contextLog: "Server",
});
// Error message (red) with file logging
buildLog({
levelLog: "error",
messageLog: "Database connection failed",
contextLog: "Database",
fileLog: "error.log", // Will append to this file
});
// Warning message (yellow)
buildLog({
levelLog: "warn",
messageLog: "Disk space running low",
contextLog: "System",
});
// Debug message (blue)
buildLog({
levelLog: "debug",
messageLog: "Connection details: 192.168.1.1:3306",
contextLog: "Network",
});CommonJS (require)
const { buildLog } = require("@dungdv/build-log");
// Basic usage with info level (green)
buildLog({
levelLog: "info",
messageLog: "Server started successfully!",
contextLog: "Server",
});
// Error message (red) with file logging
buildLog({
levelLog: "error",
messageLog: "Database connection failed",
contextLog: "Database",
fileLog: "error.log", // Will append to this file
});
// Warning message (yellow)
buildLog({
levelLog: "warn",
messageLog: "Disk space running low",
contextLog: "System",
});
// Debug message (blue)
buildLog({
levelLog: "debug",
messageLog: "Connection details: 192.168.1.1:3306",
contextLog: "Network",
});📝 API
buildLog(options)
| Option | Type | Required | Default | Description | | ---------- | -------------------------------------- | -------- | --------- | ---------------------------------- | | levelLog | 'info' | 'warn' | 'error' | 'debug' | No | 'info' | Log level that determines color | | messageLog | string | Yes | - | Message to be logged | | contextLog | string | No | '' | Context prefix for the log message | | fileLog | string | No | undefined | Filename to append logs to |
📄 License
MIT
