@@ -656,7 +656,8 @@ class Logger extends Utility implements LoggerInterface {
656656 * @deprecated This method is deprecated and will be removed in the future major versions, please use {@link appendPersistentKeys() `appendPersistentKeys()`} instead.
657657 */
658658 public setPersistentLogAttributes ( attributes : LogKeys ) : void {
659- this . #attributesStore. setPersistentAttributes ( attributes ) ;
659+ const filtered = this . #filterReservedAttributeKeys( attributes ) ;
660+ this . #attributesStore. setPersistentAttributes ( filtered ) ;
660661 }
661662
662663 /**
@@ -779,19 +780,24 @@ class Logger extends Utility implements LoggerInterface {
779780 merge ( this . powertoolsLogData , attributes ) ;
780781 }
781782
783+ #filterReservedAttributeKeys( attributes : LogKeys ) {
784+ const filtered : LogKeys = { } ;
785+ for ( const [ key , value ] of Object . entries ( attributes ) ) {
786+ if ( ! this . #checkReservedKeyAndWarn( key ) ) {
787+ filtered [ key ] = value ;
788+ }
789+ }
790+ return filtered ;
791+ }
792+
782793 /**
783794 * Shared logic for adding keys to the logger instance.
784795 *
785796 * @param attributes - The attributes to add to the log item.
786797 * @param type - The type of the attributes to add.
787798 */
788799 #appendKeys( attributes : LogKeys , type : 'temp' | 'persistent' ) : void {
789- const filtered : LogKeys = { } ;
790- for ( const [ key , value ] of Object . entries ( attributes ) ) {
791- if ( ! this . #checkReservedKeyAndWarn( key ) ) {
792- filtered [ key ] = value ;
793- }
794- }
800+ const filtered = this . #filterReservedAttributeKeys( attributes ) ;
795801 if ( type === 'temp' ) {
796802 this . #attributesStore. appendTemporaryKeys ( filtered ) ;
797803 } else {
@@ -834,7 +840,7 @@ class Logger extends Utility implements LoggerInterface {
834840 ...this . getPowertoolsLogData ( ) ,
835841 message : '' ,
836842 } ;
837- const additionalAttributes = this . #createAdditionalAttributes ( ) ;
843+ const additionalAttributes = this . #attributesStore . getAllAttributes ( ) ;
838844
839845 this . #processMainInput(
840846 input ,
@@ -849,13 +855,6 @@ class Logger extends Utility implements LoggerInterface {
849855 ) ;
850856 }
851857
852- /**
853- * Create additional attributes from persistent and temporary keys
854- */
855- #createAdditionalAttributes( ) : LogAttributes {
856- return this . #attributesStore. getAllAttributes ( ) ;
857- }
858-
859858 /**
860859 * Process the main input message and add it to the attributes
861860 */
0 commit comments