Skip to content

Commit 5cb6797

Browse files
authored
fix(logger): correct persistentLogAttributes warning behavior (#4627)
1 parent 0fa7850 commit 5cb6797

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/logger/src/Logger.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,12 @@ class Logger extends Utility implements LoggerInterface {
12911291
correlationIdSearchFn,
12921292
} = options;
12931293

1294-
if (persistentLogAttributes && persistentKeys) {
1294+
if (
1295+
persistentLogAttributes &&
1296+
Object.keys(persistentLogAttributes).length > 0 &&
1297+
persistentKeys &&
1298+
Object.keys(persistentKeys).length > 0
1299+
) {
12951300
this.warn(
12961301
'Both persistentLogAttributes and persistentKeys options were provided. Using persistentKeys as persistentLogAttributes is deprecated and will be removed in future releases'
12971302
);

packages/logger/tests/unit/workingWithkeys.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,15 @@ describe('Working with keys', () => {
622622
);
623623
});
624624

625+
it('should pass persistentKeys to child with no warning', () => {
626+
// Prepare
627+
const logger = new Logger();
628+
logger.createChild({ persistentKeys: { abc: 'xyz' } });
629+
630+
// Assess
631+
expect(console.warn).toHaveBeenCalledTimes(0);
632+
});
633+
625634
it("doesn't overwrite standard keys when appending keys", () => {
626635
// Prepare
627636
const logger = new Logger();

0 commit comments

Comments
 (0)