Skip to content

Commit 11280ad

Browse files
committed
feat(logger): log memory usage
1 parent f18c71d commit 11280ad

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/v3/middleware/update_tracker.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ export const updateTracker = () => {
4848
const message = (res.locals.message ?? '').replace(/\n|\r/g, '');
4949
const user = res.locals.currentUser;
5050

51+
const memory = process.memoryUsage();
52+
53+
const memory_usage = {
54+
rssMB: +(memory.rss / 1024 / 1024).toFixed(2),
55+
heapTotalMB: +(memory.heapTotal / 1024 / 1024).toFixed(2),
56+
heapUsedMB: +(memory.heapUsed / 1024 / 1024).toFixed(2),
57+
externalMB: +(memory.external / 1024 / 1024).toFixed(2),
58+
arrayBuffersMB: +(memory.arrayBuffers / 1024 / 1024).toFixed(2),
59+
};
60+
5161
const context = {
5262
method: req.method,
5363
status: res.statusCode,
@@ -59,6 +69,7 @@ export const updateTracker = () => {
5969
congregationId: user?.profile.congregation?.id,
6070
duration: ms,
6171
size: responseSize,
72+
memory_usage,
6273
};
6374

6475
let failedLoginAttempt = 0;

src/v3/services/logger/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const logger = (level: LogLevel, message: string, context?: Context) => {
1616
', ' +
1717
Object.entries(context)
1818
.filter(([, value]) => value !== undefined)
19-
.map(([key, value]) => `${key}="${value}"`)
19+
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
2020
.join(' ');
2121
}
2222

0 commit comments

Comments
 (0)