@@ -12,6 +12,20 @@ import { settlePromise } from './promises.js';
1212type GroupColor = Extract < AnsiColors , 'cyan' | 'magenta' > ;
1313type CiPlatform = 'GitHub Actions' | 'GitLab CI/CD' ;
1414
15+ /** Additional options for log methods */
16+ export type LogOptions = {
17+ /** Do not append line-feed to message (`process.stdout.write` instead of `console.log`) */
18+ noLineBreak ?: boolean ;
19+ /** Do not indent lines even if logged while a spinner is active */
20+ noIndent ?: boolean ;
21+ } ;
22+
23+ /** Additional options for {@link Logger.debug} method */
24+ export type DebugLogOptions = LogOptions & {
25+ /** Print debug message even if verbose flag is not set */
26+ force ?: boolean ;
27+ } ;
28+
1529const HEX_RADIX = 16 ;
1630
1731const SIGINT_CODE = 2 ;
@@ -79,9 +93,10 @@ export class Logger {
7993 * logger.error('Config file is invalid');
8094 *
8195 * @param message Error text
96+ * @param options Additional options
8297 */
83- error ( message : string ) : void {
84- this . #log( message , 'red' ) ;
98+ error ( message : string , options ?: LogOptions ) : void {
99+ this . #log( message , 'red' , options ) ;
85100 }
86101
87102 /**
@@ -93,9 +108,10 @@ export class Logger {
93108 * logger.warn('Skipping invalid audits');
94109 *
95110 * @param message Warning text
111+ * @param options Additional options
96112 */
97- warn ( message : string ) : void {
98- this . #log( message , 'yellow' ) ;
113+ warn ( message : string , options ?: LogOptions ) : void {
114+ this . #log( message , 'yellow' , options ) ;
99115 }
100116
101117 /**
@@ -107,9 +123,10 @@ export class Logger {
107123 * logger.info('Code PushUp CLI v0.80.2');
108124 *
109125 * @param message Info text
126+ * @param options Additional options
110127 */
111- info ( message : string ) : void {
112- this . #log( message ) ;
128+ info ( message : string , options ?: LogOptions ) : void {
129+ this . #log( message , undefined , options ) ;
113130 }
114131
115132 /**
@@ -122,11 +139,10 @@ export class Logger {
122139 *
123140 * @param message Debug text
124141 * @param options Additional options
125- * @param options.force Print debug message even if verbose flag is not set
126142 */
127- debug ( message : string , options ?: { force ?: boolean } ) : void {
143+ debug ( message : string , options ?: DebugLogOptions ) : void {
128144 if ( this . #isVerbose || options ?. force ) {
129- this . #log( message , 'gray' ) ;
145+ this . #log( message , 'gray' , options ) ;
130146 }
131147 }
132148
@@ -457,17 +473,24 @@ export class Logger {
457473 return result . value ;
458474 }
459475
460- #log( message : string , color ?: AnsiColors ) : void {
476+ #log( message : string , color ?: AnsiColors , options ?: LogOptions ) : void {
477+ const print : ( text : string ) => void = options ?. noLineBreak
478+ ? text => process . stdout . write ( text )
479+ : console . log ;
480+
461481 if ( this . #activeSpinner) {
462482 if ( this . #activeSpinner. isSpinning ) {
463483 this . #activeSpinnerLogs. push ( this . #format( message , color ) ) ;
464484 } else {
465- console . log ( this . #format( indentLines ( message , 2 ) , color ) ) ;
485+ const indented =
486+ options ?. noIndent || ! message ? message : indentLines ( message , 2 ) ;
487+ print ( this . #format( indented , color ) ) ;
466488 }
467489 } else {
468- console . log ( this . #format( message , color ) ) ;
490+ print ( this . #format( message , color ) ) ;
469491 }
470- this . #endsWithBlankLine = ! message || message . endsWith ( '\n' ) ;
492+ this . #endsWithBlankLine =
493+ ( ! message || message . endsWith ( '\n' ) ) && ! options ?. noIndent ;
471494 }
472495
473496 #format( message : string , color : AnsiColors | undefined ) : string {
0 commit comments