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

Commit 93bbb31

Browse files
author
Michal Vlasák
committed
✨Add global enable to override default disable
1 parent 77dbd7f commit 93bbb31

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/serializers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ const disablePaths = (paths?: string[]) => {
100100

101101
const enablePaths = (paths?: string[]) => {
102102
forEach(serializers, (value, key) => {
103+
if (paths && paths.includes(key)) {
104+
delete serializers[key];
105+
return;
106+
}
103107
const affectedFields = sliceByPrefix(`${key}.`, paths);
104108

105109
if (affectedFields.length === 0) return;

src/tests/serializers.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,33 @@ test('Enable custom path', () => {
261261
expect(loggerWrites).toBeCalled();
262262
});
263263

264+
test('Enable all from response', () => {
265+
const loggerWrites = jest.fn();
266+
const res = {
267+
out: 'out data',
268+
test: 'test',
269+
};
270+
271+
const logger = loggerFactory({
272+
enableFields: ['res'],
273+
streams: [
274+
{
275+
stream: new Writable({
276+
write: (chunk, encoding, next) => {
277+
const json = JSON.parse(chunk);
278+
expect(json.res).toEqual(res);
279+
loggerWrites();
280+
next();
281+
},
282+
}),
283+
},
284+
],
285+
});
286+
287+
logger.info({ res });
288+
expect(loggerWrites).toBeCalled();
289+
})
290+
264291
test('Some express headers are enabled by default', () => {
265292
const loggerWrites = jest.fn();
266293
const logger = loggerFactory({

0 commit comments

Comments
 (0)