Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit d05caa4

Browse files
author
Michal Vlasák
committed
🔥 Remove time and user agent from express messages
1 parent a0377ec commit d05caa4

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/express.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ const expressOnFinished = (logger: Cosmas, req: AckeeRequest) => (_err: Error |
2828
}
2929
const error = res[errorSymbol];
3030
const userAgent = req.headers['user-agent'];
31-
const reqOut = `${res.statusCode} ${req.method} ${req.originalUrl} ${res.time} ms ${userAgent ? userAgent : ''}`;
31+
const reqOut = `${res.statusCode} ${req.method} ${req.originalUrl}`;
3232
const standardOutput = {
3333
data: {
3434
req,
3535
res,
36+
userAgent,
3637
ackId: req.ackId,
3738
},
3839
message: `${reqOut} - Standard output`,
@@ -55,8 +56,7 @@ const expressMiddleware: RequestHandler = function(
5556
response: AckeeResponse,
5657
next: any
5758
) {
58-
const userAgent = req.headers['user-agent'];
59-
const reqIn = `--- ${req.method} ${req.originalUrl} ${userAgent ? userAgent : ''}`;
59+
const reqIn = `--- ${req.method} ${req.originalUrl}`;
6060
if (!shouldSkipLogging(this, req)) {
6161
this.debug({ req, ackId: req.ackId }, `${reqIn} - Request accepted`);
6262
}

src/tests/express.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ test('route can be ignored using regexp helper', () => {
125125
});
126126
});
127127

128-
test('user-agent is logged', () => {
128+
test('user-agent is not logged', () => {
129129
const loggerWrites = jest.fn();
130130
const logger = loggerFactory({
131131
streams: [
132132
{
133133
stream: new Writable({
134134
write: (chunk, encoding, next) => {
135135
const json = JSON.parse(chunk);
136-
expect(json.message).toMatch('dummy agent');
136+
expect(json.message).not.toMatch('dummy agent');
137137
loggerWrites();
138138
next();
139139
},

0 commit comments

Comments
 (0)