azify-logger 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/middleware-express.js +11 -2
- package/middleware-restify.js +14 -2
- package/package.json +1 -1
package/middleware-express.js
CHANGED
|
@@ -382,8 +382,17 @@ function createExpressLoggingMiddleware(options = {}) {
|
|
|
382
382
|
|
|
383
383
|
const statusCode = res._actualStatusCode || res._statusCode || res.statusCode || 200
|
|
384
384
|
|
|
385
|
+
let parsedResponseBody = serializedResponseBody
|
|
386
|
+
try {
|
|
387
|
+
if (typeof serializedResponseBody === 'string' && serializedResponseBody.trim().startsWith('{')) {
|
|
388
|
+
parsedResponseBody = JSON.parse(serializedResponseBody)
|
|
389
|
+
} else if (typeof serializedResponseBody === 'string' && serializedResponseBody.trim().startsWith('[')) {
|
|
390
|
+
parsedResponseBody = JSON.parse(serializedResponseBody)
|
|
391
|
+
}
|
|
392
|
+
} catch (_) {}
|
|
393
|
+
|
|
385
394
|
const responseMessage = serializedResponseBody && serializedResponseBody.length > 0
|
|
386
|
-
? `[RESPONSE] ${
|
|
395
|
+
? `[RESPONSE] ${req.method} ${req.url} ${statusCode}`
|
|
387
396
|
: `[RESPONSE] ${req.method} ${req.url} ${statusCode} ${duration}ms`
|
|
388
397
|
|
|
389
398
|
const responseData = {
|
|
@@ -392,7 +401,7 @@ function createExpressLoggingMiddleware(options = {}) {
|
|
|
392
401
|
statusCode: statusCode,
|
|
393
402
|
responseTime: duration,
|
|
394
403
|
responseHeaders: res.getHeaders ? res.getHeaders() : {},
|
|
395
|
-
responseBody:
|
|
404
|
+
responseBody: parsedResponseBody // Use parsed object instead of string
|
|
396
405
|
}
|
|
397
406
|
|
|
398
407
|
try { res._azifyResponseLogged = true } catch (_) {}
|
package/middleware-restify.js
CHANGED
|
@@ -282,8 +282,20 @@ function createRestifyLoggingMiddleware(options = {}) {
|
|
|
282
282
|
|
|
283
283
|
const statusCode = res._actualStatusCode || res._statusCode || res.statusCode || 200
|
|
284
284
|
|
|
285
|
+
// Try to parse serializedResponseBody back to object for cleaner display in Grafana
|
|
286
|
+
let parsedResponseBody = serializedResponseBody
|
|
287
|
+
try {
|
|
288
|
+
if (typeof serializedResponseBody === 'string' && serializedResponseBody.trim().startsWith('{')) {
|
|
289
|
+
parsedResponseBody = JSON.parse(serializedResponseBody)
|
|
290
|
+
} else if (typeof serializedResponseBody === 'string' && serializedResponseBody.trim().startsWith('[')) {
|
|
291
|
+
parsedResponseBody = JSON.parse(serializedResponseBody)
|
|
292
|
+
}
|
|
293
|
+
} catch (_) {
|
|
294
|
+
// Keep as string if parsing fails
|
|
295
|
+
}
|
|
296
|
+
|
|
285
297
|
const responseMessage = serializedResponseBody && serializedResponseBody.length > 0
|
|
286
|
-
? `[RESPONSE] ${
|
|
298
|
+
? `[RESPONSE] ${req.method} ${req.url} ${statusCode}`
|
|
287
299
|
: `[RESPONSE] ${req.method} ${req.url} ${statusCode} ${duration}ms`
|
|
288
300
|
|
|
289
301
|
const responseData = {
|
|
@@ -292,7 +304,7 @@ function createRestifyLoggingMiddleware(options = {}) {
|
|
|
292
304
|
statusCode: statusCode,
|
|
293
305
|
responseTime: duration,
|
|
294
306
|
responseHeaders: res.getHeaders ? res.getHeaders() : {},
|
|
295
|
-
responseBody:
|
|
307
|
+
responseBody: parsedResponseBody // Use parsed object instead of string
|
|
296
308
|
}
|
|
297
309
|
|
|
298
310
|
try { res._azifyResponseLogged = true } catch (_) {}
|