@@ -310,7 +310,8 @@ export class Logger {
310310 #stdoutLogger?: Logger
311311 #stderrIndention = ''
312312 #stdoutIndention = ''
313- #lastWasBlank = false
313+ #stderrLastWasBlank = false
314+ #stdoutLastWasBlank = false
314315 #logCallCount = 0
315316 #constructorArgs: unknown [ ]
316317 #options: Record < string , unknown >
@@ -460,6 +461,30 @@ export class Logger {
460461 }
461462 }
462463
464+ /**
465+ * Get lastWasBlank state for a specific stream.
466+ * @private
467+ */
468+ #getLastWasBlank( stream : 'stderr' | 'stdout' ) : boolean {
469+ const root = this . #getRoot( )
470+ return stream === 'stderr'
471+ ? root . #stderrLastWasBlank
472+ : root . #stdoutLastWasBlank
473+ }
474+
475+ /**
476+ * Set lastWasBlank state for a specific stream.
477+ * @private
478+ */
479+ #setLastWasBlank( stream : 'stderr' | 'stdout' , value : boolean ) : void {
480+ const root = this . #getRoot( )
481+ if ( stream === 'stderr' ) {
482+ root . #stderrLastWasBlank = value
483+ } else {
484+ root . #stdoutLastWasBlank = value
485+ }
486+ }
487+
463488 /**
464489 * Get the target stream for this logger instance.
465490 * @private
@@ -492,7 +517,7 @@ export class Logger {
492517 con ,
493518 logArgs ,
494519 )
495- this [ lastWasBlankSymbol ] ( hasText && isBlankString ( logArgs [ 0 ] ) )
520+ this [ lastWasBlankSymbol ] ( hasText && isBlankString ( logArgs [ 0 ] ) , targetStream )
496521 ; ( this as any ) [ incLogCallCountSymbol ] ( )
497522 return this
498523 }
@@ -533,7 +558,7 @@ export class Logger {
533558 } ) ,
534559 ...extras ,
535560 )
536- this . #lastWasBlank = false
561+ this [ lastWasBlankSymbol ] ( false , 'stderr' )
537562 ; ( this as any ) [ incLogCallCountSymbol ] ( )
538563 return this
539564 }
@@ -554,7 +579,8 @@ export class Logger {
554579 * ```
555580 */
556581 get logCallCount ( ) {
557- return this . #logCallCount
582+ const root = this . #getRoot( )
583+ return root . #logCallCount
558584 }
559585
560586 /**
@@ -566,7 +592,8 @@ export class Logger {
566592 * @returns The logger instance for chaining
567593 */
568594 [ incLogCallCountSymbol ] ( ) {
569- this . #logCallCount += 1
595+ const root = this . #getRoot( )
596+ root . #logCallCount += 1
570597 return this
571598 }
572599
@@ -577,10 +604,21 @@ export class Logger {
577604 * This is called automatically by logging methods.
578605 *
579606 * @param value - Whether the last line was blank
607+ * @param stream - Optional stream to update (defaults to both streams if not bound, or target stream if bound)
580608 * @returns The logger instance for chaining
581609 */
582- [ lastWasBlankSymbol ] ( value : unknown ) : this {
583- this . #lastWasBlank = ! ! value
610+ [ lastWasBlankSymbol ] ( value : unknown , stream ?: 'stderr' | 'stdout' ) : this {
611+ if ( stream ) {
612+ // Explicit stream specified
613+ this . #setLastWasBlank( stream , ! ! value )
614+ } else if ( this . #boundStream) {
615+ // Stream-bound logger - affect only the bound stream
616+ this . #setLastWasBlank( this . #boundStream, ! ! value )
617+ } else {
618+ // Root logger with no stream specified - affect both streams
619+ this . #setLastWasBlank( 'stderr' , ! ! value )
620+ this . #setLastWasBlank( 'stdout' , ! ! value )
621+ }
584622 return this
585623 }
586624
@@ -827,7 +865,7 @@ export class Logger {
827865 * ```
828866 */
829867 errorNewline ( ) {
830- return this . #lastWasBlank ? this : this . error ( '' )
868+ return this . #getLastWasBlank ( 'stderr' ) ? this : this . error ( '' )
831869 }
832870
833871 /**
@@ -1040,7 +1078,7 @@ export class Logger {
10401078 * ```
10411079 */
10421080 logNewline ( ) {
1043- return this . #lastWasBlank ? this : this . log ( '' )
1081+ return this . #getLastWasBlank ( 'stdout' ) ? this : this . log ( '' )
10441082 }
10451083
10461084 /**
@@ -1103,7 +1141,7 @@ export class Logger {
11031141 */
11041142 step ( msg : string , ...extras : unknown [ ] ) : this {
11051143 // Add blank line before the step message.
1106- if ( ! this . #lastWasBlank ) {
1144+ if ( ! this . #getLastWasBlank ( 'stdout' ) ) {
11071145 // Use this.log() to properly track the blank line.
11081146 this . log ( '' )
11091147 }
0 commit comments