This variant uses MongoDB + Mongoose.
Quick start:
- Install dependencies:
npm install- Set environment:
MONGODB_URI=mongodb://user:pass@localhost:27017/logdb
JWT_SECRET=your_jwt_secret
PORT=4000
SERVICE_NAME=logging-service
- Start the server:
npm start- Seed demo data (optional):
npm run seed- Generate a test admin JWT (example using node):
const jwt = require('jsonwebtoken');
const token = jwt.sign({ id: 'admin1', role: 'admin', name: 'Admin' }, process.env.JWT_SECRET || 'replace_this_with_a_strong_secret');
console.log(token);API overview (high level):
- POST /logs
- POST /errors
- GET /logs (admin)
- GET /errors (admin)
- GET /errors/:fingerprint (admin)
- POST /errors/:fingerprint/resolve (admin)
- GET /alerts (admin)
Notes & tradeoffs:
- Uses MongoDB for append-heavy storage and flexible JSON fields.
- Retention cleanup runs daily; adjust via LOG_RETENTION_DAYS.
- Alerts are simulated (console + alerts collection). Configure ALERT_WEBHOOK_URL to forward.
- Sanitization is heuristic: adapt regexes for your PII rules.