Skip to content

Commit

Permalink
fix: remove log query string from url for every ctx log
Browse files Browse the repository at this point in the history
  • Loading branch information
goshander committed Oct 14, 2024
1 parent 9da8f4f commit d52865d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/base-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function setupBaseMiddleware(ctx: AppContext, expressApp: Express) {
req.ctx.addLoggerExtra('req', {
id: req.id,
method: req.method,
url: ctx.utils.redactSensitiveQueryParams(req.url),
url: ctx.utils.redactSensitiveQueryParams(req.path),
});

const requestStartedExtra = ctx.config.appDevMode
Expand Down
20 changes: 18 additions & 2 deletions src/tests/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('log system', () => {
req: {
id: requestId,
method: 'GET',
url: `/log?q=${query}`,
url: '/log',
},
res: {
statusCode: '200',
Expand All @@ -250,9 +250,25 @@ describe('log system', () => {
req: {
id: requestId,
method: 'GET',
url: `/log?q=${query}`,
url: '/log',
},
query,
});

// first log with request
log = JSON.parse(logger.write.mock.calls?.pop() || '{}');

// check request log
expect(log).toMatchObject({
msg: `[Express GET] Request started [${requestId}]`,
level: 30,
name: APP_NAME,
time: expect.any(Number),
req: {
id: requestId,
method: 'GET',
url: `/log?q=${query}`,
},
});
});
});

0 comments on commit d52865d

Please sign in to comment.