@@ -761,25 +761,29 @@ class Logger extends Utility implements LoggerInterface {
761761 * @see {@link ConstructorOptions.jsonReplacerFn }
762762 */
763763 protected getJsonReplacer ( ) : ( key : string , value : unknown ) => void {
764- const references = new WeakSet ( ) ;
764+ const ancestors : unknown [ ] = [ ] ;
765+ const jsonReplacerFn = this . #jsonReplacerFn;
766+ const logFormatter = this . getLogFormatter ( ) ;
765767
766- return ( key , value ) => {
768+ return function ( this : unknown , key : string , value : unknown ) {
767769 let replacedValue = value ;
768- if ( this . #jsonReplacerFn)
769- replacedValue = this . #jsonReplacerFn?.( key , replacedValue ) ;
770+ if ( jsonReplacerFn ) replacedValue = jsonReplacerFn ( key , replacedValue ) ;
770771
771772 if ( replacedValue instanceof Error ) {
772- replacedValue = this . getLogFormatter ( ) . formatError ( replacedValue ) ;
773+ replacedValue = logFormatter . formatError ( replacedValue ) ;
773774 }
774775 if ( typeof replacedValue === 'bigint' ) {
775776 return replacedValue . toString ( ) ;
776777 }
777778 if ( typeof replacedValue === 'object' && replacedValue !== null ) {
779+ while ( ancestors . length > 0 && ancestors . at ( - 1 ) !== this ) {
780+ ancestors . pop ( ) ;
781+ }
778782 /* v8 ignore next -- @preserve */
779- if ( references . has ( replacedValue ) ) {
783+ if ( ancestors . includes ( replacedValue ) ) {
780784 return ;
781785 }
782- references . add ( replacedValue ) ;
786+ ancestors . push ( replacedValue ) ;
783787 }
784788
785789 return replacedValue ;
0 commit comments