https://github.com/anibalalpizar/audit-log-middleware
🌟 Automated audit logging system with JSON/CSV support.
https://github.com/anibalalpizar/audit-log-middleware
audit-logs csv json logging-system npm-package typescript
Last synced: 3 months ago
JSON representation
🌟 Automated audit logging system with JSON/CSV support.
- Host: GitHub
- URL: https://github.com/anibalalpizar/audit-log-middleware
- Owner: anibalalpizar
- License: mit
- Created: 2024-12-10T03:42:16.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-10T09:06:38.000Z (over 1 year ago)
- Last Synced: 2025-10-22T11:38:46.822Z (7 months ago)
- Topics: audit-logs, csv, json, logging-system, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/audit-log-middleware
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🎯 Audit Log Middleware
A powerful middleware for logging user activities in your Express applications.
## ✨ Features
- 📝 Automatically captures relevant data:
- User information
- Endpoint accessed
- HTTP method
- Date and time
- Request body details
- 🔧 Configurable detail levels (basic, intermediate, complete)
- 💾 Export options:
- JSON files
- CSV files
- External services (Elasticsearch)
## 🎯 Use Cases
- 📋 Applications requiring audit trails (e.g., GDPR or HIPAA compliance)
- 📊 Internal application monitoring
- 🔍 User activity tracking
- 🛡️ Security logging
## 🚀 Installation
```bash
npm install audit-log-middleware
```
## 📖 Basic Usage
```javascript
const express = require("express");
const { createAuditMiddleware } = require("audit-log-middleware");
const app = express();
// Basic audit middleware configuration
const auditMiddleware = createAuditMiddleware({
level: "complete",
storage: {
type: "file",
options: {
filename: "audit-logs.json",
},
},
});
// Apply middleware globally
app.use(auditMiddleware);
```
## 📝 Example Output
```json
[
{
"timestamp": "2024-01-01T12:00:00.000Z",
"userId": "user123",
"method": "GET",
"endpoint": "/users/1",
"userAgent": "Mozilla/5.0 (compatible; ExampleBrowser/1.0)",
"ip": "71.198.38.7",
"responseStatus": 200
},
{
"timestamp": "2024-01-01T12:01:00.000Z",
"userId": "user123",
"method": "GET",
"endpoint": "/",
"userAgent": "Mozilla/5.0 (compatible; ExampleBrowser/1.0)",
"ip": "216.73.163.219",
"responseStatus": 200,
"responseBody": "{\"message\":\"Hello World!\"}"
}
]
```
## ⚙️ Configuration Options
### Detail Levels
- `basic`: Logs only essential information
- `intermediate`: Adds request headers and response status
- `complete`: Includes full request and response details
### Storage Options
```javascript
// File storage
{
type: 'file',
options: {
filename: 'audit-logs.json'
}
}
// Elasticsearch storage
{
type: 'elasticsearch',
options: {
node: 'http://localhost:9200',
index: 'audit-logs'
}
}
```
## 🔒 Security Considerations
- Sensitive data can be filtered out using the `exclude` option
- Supports data encryption for stored logs
- Compliant with common security standards
## 🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## 📄 License
This project is licensed under the MIT License - see the LICENSE file for details.