UNPKG

log-vista

Version:

This is a project which capture logs and stores in database and display on web inreal time

127 lines (98 loc) β€’ 3.76 kB
# Logvista **Logvista** is a self-hosted log ingestion service. ## πŸ“¦ Install ```bash npm install log-vista ``` ## βš™οΈ Initialize ```bash npx logvista init ``` ## πŸš€ Start Server ```bash npx logvista start ``` ## πŸ“€ Send Logs ```bash curl -X POST http://localhost:5566/logs -H "Content-Type: application/json" -d '{ "timestamp": "2025-06-05T18:20:00Z", "level": "error", "message": "Payment failed", "tag": "user", "metadata": {"userId": "123"}, "projectId": "xxx", "clientId": "yyy" }' ``` ## πŸ“₯ Retrieve Logs ```bash curl 'http://localhost:5566/logs?projectId=xxx&clientId=yyy&page=1&limit=50' ``` --- MIT License Β© Your Name # πŸŽ‰ Custom Logger An efficient, customizable, and easy-to-use logging library for Node.js applications! This logger captures various log levels (info, warning, error, etc.), stores them in a MySQL database, and displays logs in a structured JSON format on the console/terminal. Ideal for real-time log tracking with an optional server! ## ✨ Features - πŸ”Ή **Log Levels**: Manage logs across levelsβ€”info, warn, error, etc. - πŸ”Ή **Database Storage**: Logs are saved to MySQL using connection pooling for efficient performance. - πŸ”Ή **JSON Output**: Logs appear in clean JSON with timestamps for clarity. - πŸ”Ή **Real-Time Viewing (Optional)**: Track logs live with the optional server. - πŸ”Ή **Configurable Setup**: Quick setup with `config.json`. ## πŸ“₯ Installation Install the package: ```bash npm install customlogger ``` πŸ›  Prerequisites Node.js (latest stable version) MySQL Database mysql2 npm package for MySQL support ## πŸš€ Quick Start 1️⃣ Configure Your Database Create a config.json file in your project root: ```json { "host": "your_mysql_host", "user": "your_database_user", "password": "your_database_password", "database": "your_database_name", "port": 3306 } ``` 2️⃣ Import and Initialize Logger In your main file, import the logger and initialize the database: ```javascript const { logMessage, initializeDatabase } = require('customlogger'); // Initialize the database initializeDatabase(); ``` 3️⃣ Log Your Messages Add logs across various levels like so: ```javascript Copy code (async () => { const now = new Date().toISOString(); await logMessage('info', 'This is an info message', { key: 'value' }, now); await logMessage('warn', 'This is a warning', { warningCode: 101 }, now); await logMessage('error', 'This is an error message', { errorCode: 'E500' }, now); })(); ``` ## πŸ“‚ Project Structure ```plaintext src/ β”œβ”€β”€ cli.js # Command-line interface script β”œβ”€β”€ index.js # Main logging functionality β”œβ”€β”€ database.js # Database connection logic using connection pooling └── server.js # Optional server for real-time log viewing config.json package.json ``` ## πŸƒ Running Your Application To start logging, run your main file: ```bash node your_main_file.js ``` ## πŸ“ Example Log Output ```json {"level":"info","message":"This is an info message","metadata":{"key":"value"},"timestamp":"2024-10-30T19:04:31.758Z"} ``` ## πŸ›  Troubleshooting ⚠️ Database Connection Issues: Make sure MySQL is running, and credentials in config.json are correct. ⚠️ Date Format Errors: Use YYYY-MM-DD HH:MM:SS format for timestamp to avoid issues when saving logs to the database. ## πŸ’‘ License This project is licensed under the MIT License. ## 🀝 Contributing Contributions are welcome! For major changes, open an issue first to discuss what you’d like to modify. ## πŸŽ‰ Thank you for using Custom Logger! Happy Logging! πŸš€