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

Commit 6ff45c4

Browse files
authored
Merge pull request #37 from AckeeCZ/feat/remove-time-and-agent
🔥 Remove time and user agent from express messages
2 parents a0377ec + 68c4921 commit 6ff45c4

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### Changed
99
- `pino.pretty` replaced with `util.inspect`
1010
- rename interfaces
11+
- removed user agent and response time from express middleware logs
1112

1213
## [1.1.0] - 2019-08-05
1314

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)