Skip to content

Commit fe6715c

Browse files
committed
chore: add tests for child logging
1 parent 0a59ef1 commit fe6715c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pino, { BaseLogger, DestinationStream, LoggerOptions, LevelMapping } from 'pino';
1+
import pino, { BaseLogger, DestinationStream, LoggerOptions, LevelMapping, Bindings } from 'pino';
22
import { GlobalContextStorageProvider, ContextStorageProvider, ContextMap } from './context';
33

44
export interface ExtendedPinoOptions extends LoggerOptions {

src/tests/index.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ tap.test('should log an error message with apiRequestId', (t) => {
4747
t.end();
4848
});
4949

50+
tap.test('should add tags with a child logger', (t) => {
51+
const [log, output] = createLogger();
52+
const childLogger = log.child({ userId: 12 });
53+
54+
log.withRequest({}, { awsRequestId: '9048989' });
55+
childLogger.info('Message with userId');
56+
t.matchSnapshot(output.buffer);
57+
t.end();
58+
});
59+
5060
/**
5161
* Creates a test logger and output buffer for assertions
5262
* Returns the logger and the buffer

tap-snapshots/src-tests-index.spec.ts-TAP.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8+
exports[`src/tests/index.spec.ts TAP should add tags with a child logger > must match snapshot 1`] = `
9+
2016-12-01T06:00:00.000Z 9048989 INFO Message with userId {"level":30,"time":1480572000000,"userId":12,"awsRequestId":"9048989","x-correlation-id":"9048989","msg":"Message with userId"}
10+
`
11+
812
exports[`src/tests/index.spec.ts TAP should log a simple info message > must match snapshot 1`] = `
913
2016-12-01T06:00:00.000Z undefined INFO Simple message {"level":30,"time":1480572000000,"msg":"Simple message"}
1014
`

0 commit comments

Comments
 (0)