sai-sequelize
v1.0.2
Published
A Sequelize based module which automatically captures all logs of nodeJS applications
Downloads
3
Readme
sai-sequelize
sai-sequelize
is a Node.js module built on top of Sequelize, designed to automatically capture and store log messages from your application into a MySQL database. It intercepts console logs and errors, making it easier to persist logs for later retrieval and analysis.
Features
- Easy integration with any Express.js application.
- Automatically captures and stores console logs and errors in a MySQL database.
- Provides a simple API to retrieve stored logs for monitoring and debugging.
Prerequisites
Before you begin, ensure you have met the following requirements:
- Node.js installed on your machine.
- A MySQL database is accessible.
Installation
Install sai-sequelize
using npm:
npm install sai-sequelize
Usage
Here's how to integrate sai-sequelize
into your Node.js application:
- Initialize sai-sequelize with your database configuration:
const saiSequelize = require('sai-sequelize');
saiSequelize.initialization({
host: "your_database_host",
username: "your_database_username",
password: "your_database_password",
database: "your_database_name",
dialect: "mysql" // or another supported dialect
}).catch(err => {
console.error('Failed to initialize sai-sequelize:', err);
});
Retrieve stored logs
You can retrieve stored logs using the getLogs method. For example, to display logs on an Express route
app.get('/logs', async (req, res) => {
const logs = await saiSequelize.getLogs();
res.json(logs);
});
Optionally, intercept standard console logs and errors:
saiSequelize.interceptConsoleLogs();