logginglogger
v1.0.1
Published
A lightweight, colorful TypeScript logger for Node.js with success, error, warning, and info logging utilities powered by Chalk.
Downloads
0
Maintainers
Readme
logginglogger
A simple, colorful, and lightweight logging utility for Node.js built with TypeScript and Chalk.
logginglogger provides four logging methods — successLog, errorLog, warningLog, and infoLog — to display clear, color-coded console messages.
✨ Features
- 🟢 Success logs — Green, bold messages for successful operations.
- 🔴 Error logs — Red, bold messages for errors and failures.
- 🟡 Warning logs — Yellow, bold messages for warnings.
- 🔵 Info logs — Cyan, bold messages for informational updates.
- 🎨 Colored output powered by Chalk.
- 📏 Dynamic log separators based on message length, capped at 80 characters.
- ⚡ Default messages when no message is provided.
- 📦 Written in TypeScript with type-safe action names.
📦 Installation
Install the package:
npm install logginglogger🚀 Usage
Import the logging functions into your project:
import { successLog, errorLog, warningLog, infoLog } from "logginglogger";
successLog("Server started successfully");
errorLog("Database connection failed");
warningLog("Proceed with caution");
infoLog("Waiting for incoming requests");💡 Examples
1. Server Startup
Use logging messages to indicate when your application starts.
import { successLog, infoLog } from "logginglogger";
infoLog("Starting server...");
successLog("Server is running on port 4000");2. Database Connection
Log successful database connections and connection failures.
import mongoose from "mongoose";
import { successLog, errorLog } from "logginglogger";
mongoose
.connect(process.env.DB!)
.then(() => {
successLog("Database connected successfully");
})
.catch((error) => {
errorLog(`Database connection failed: ${error.message}`);
});3. API Request Handling
Display informational messages when handling API requests.
import express from "express";
import { infoLog, successLog, errorLog } from "logginglogger";
const app = express();
app.get("/api/users", (req, res) => {
infoLog("GET /api/users");
try {
const users = [{ id: 1, name: "John" }];
successLog("Users fetched successfully");
res.json(users);
} catch {
errorLog("Failed to fetch users");
res.status(500).json({ message: "Internal server error" });
}
});
app.listen(4000, () => {
successLog("API server started on port 4000");
});4. Input Validation
Use warnings to indicate missing or invalid input.
import { warningLog, successLog } from "logginglogger";
const username = "Sujit";
if (!username) {
warningLog("Username is required");
} else {
successLog("Username validation passed");
}5. Default Messages
Each logging function has a default message, so you can call it without arguments.
successLog();
// Operation Completed Successfully
errorLog();
// Something went wrong during execution
warningLog();
// Proceed with caution
infoLog();
// Awaiting Response🎨 Log Types
| Function | Color | Default Message |
| -------------- | ------ | ------------------------------------- |
| successLog() | Green | Operation Completed Successfully |
| errorLog() | Red | Something went wrong during execution |
| warningLog() | Yellow | Proceed with caution |
| infoLog() | Cyan | Awaiting Response |
🖥️ Example Output
The terminal displays a colored message surrounded by matching separators.
--------------------------------------------------
SUCCESS - Server started successfully
--------------------------------------------------The separator length depends on the message length, up to 80 characters. Colors are applied in the terminal using Chalk.
⚙️ How It Works
The logger uses a shared handler() function to format all messages.
- Calculate the separator length based on the message and action lengths.
- Limit the separator to a maximum of 80 characters.
- Apply colors using Chalk's color and formatting methods.
- Print the output with a separator above and below the log message.
The supported action types are:
type ActionType = "SUCCESS" | "ERROR" | "WARNING" | "INFO";🛠️ Technologies Used
- TypeScript — Type-safe development.
- Chalk — Terminal text styling.
- Node.js — JavaScript runtime.
📁 Project Structure
logginglogger/
├── src/
│ └── index.ts
├── dist/
│ ├── index.js
│ └── index.d.ts
├── package.json
├── tsconfig.json
├── README.md
└── .gitignore📋 Requirements
- Node.js
- npm
TypeScript is required when developing the package from source.
🤝 Contributing
Contributions, bug reports, and feature suggestions are welcome.
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Submit a pull request.
📄 License
This project is licensed under the ISC License.
logginglogger — Make your terminal logs clear, colorful, and easy to read.
