diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index bb46a499e6..9c409d6d26 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -1291,7 +1291,12 @@ class Logger extends Utility implements LoggerInterface { correlationIdSearchFn, } = options; - if (persistentLogAttributes && persistentKeys) { + if ( + persistentLogAttributes && + Object.keys(persistentLogAttributes).length > 0 && + persistentKeys && + Object.keys(persistentKeys).length > 0 + ) { this.warn( 'Both persistentLogAttributes and persistentKeys options were provided. Using persistentKeys as persistentLogAttributes is deprecated and will be removed in future releases' ); diff --git a/packages/logger/tests/unit/workingWithkeys.test.ts b/packages/logger/tests/unit/workingWithkeys.test.ts index f921ef9b12..64c7b60c67 100644 --- a/packages/logger/tests/unit/workingWithkeys.test.ts +++ b/packages/logger/tests/unit/workingWithkeys.test.ts @@ -622,6 +622,15 @@ describe('Working with keys', () => { ); }); + it('should pass persistentKeys to child with no warning', () => { + // Prepare + const logger = new Logger(); + logger.createChild({ persistentKeys: { abc: 'xyz' } }); + + // Assess + expect(console.warn).toHaveBeenCalledTimes(0); + }); + it("doesn't overwrite standard keys when appending keys", () => { // Prepare const logger = new Logger();