Mbonea Claude Sonnet 4.6 commited on
Commit
a2c9e74
Β·
1 Parent(s): dfe7dfc

feat(logging): full Omada request/response logging and HTTP request logger

Browse files

- Omada: log request body and full (untruncated) response per call
- Express: log every incoming request with method, URL, body, status
code, and response time

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. src/app.js +10 -0
  2. src/services/omada.js +1 -1
src/app.js CHANGED
@@ -17,6 +17,16 @@ app.use(express.static(path.join(__dirname, '..', 'public')));
17
  // ── Middleware ────────────────────────────────────────────────────────────────
18
  app.use(cors());
19
 
 
 
 
 
 
 
 
 
 
 
20
  // NOTE: /api/webhooks/snippe needs raw body β€” mount it BEFORE json middleware
21
  app.use('/api/webhooks', require('./routes/webhooks.routes'));
22
 
 
17
  // ── Middleware ────────────────────────────────────────────────────────────────
18
  app.use(cors());
19
 
20
+ // Request logger
21
+ app.use((req, res, next) => {
22
+ const start = Date.now();
23
+ res.on('finish', () => {
24
+ const body = req.body && Object.keys(req.body).length ? ' body=' + JSON.stringify(req.body) : '';
25
+ console.log(`[http] ${req.method} ${req.originalUrl}${body} β†’ ${res.statusCode} (${Date.now() - start}ms)`);
26
+ });
27
+ next();
28
+ });
29
+
30
  // NOTE: /api/webhooks/snippe needs raw body β€” mount it BEFORE json middleware
31
  app.use('/api/webhooks', require('./routes/webhooks.routes'));
32
 
src/services/omada.js CHANGED
@@ -71,7 +71,7 @@ async function omadaRequest(method, path, data = null, retried = false) {
71
  return omadaRequest(method, path, data, true);
72
  }
73
 
74
- console.log(`[omada] ${method} ${path} β†’ errorCode=${res.data.errorCode} result=`, JSON.stringify(res.data.result ?? res.data.msg).slice(0, 300));
75
 
76
  if (res.data.errorCode !== 0) {
77
  const err = new Error(res.data.msg || `Omada error ${res.data.errorCode}`);
 
71
  return omadaRequest(method, path, data, true);
72
  }
73
 
74
+ console.log(`[omada] ${method} ${path}${data ? ' body=' + JSON.stringify(data) : ''} β†’ errorCode=${res.data.errorCode} result=${JSON.stringify(res.data.result ?? res.data.msg)}`);
75
 
76
  if (res.data.errorCode !== 0) {
77
  const err = new Error(res.data.msg || `Omada error ${res.data.errorCode}`);