Ali-Amir-code / t10-activity-logging

Repository from Github https://github.comAli-Amir-code/t10-activity-loggingRepository from Github https://github.comAli-Amir-code/t10-activity-logging

Activity Logging & Error Monitoring API

This variant uses MongoDB + Mongoose.

Quick start:

  1. Install dependencies:
npm install
  1. Set environment:
MONGODB_URI=mongodb://user:pass@localhost:27017/logdb
JWT_SECRET=your_jwt_secret
PORT=4000
SERVICE_NAME=logging-service
  1. Start the server:
npm start
  1. Seed demo data (optional):
npm run seed
  1. 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.

About


Languages

Language:JavaScript 100.0%