import { figures } from './figures' ; import { LogLevels } from './logger.constants' ; import { LoggerOptions } from './logger.interface' ; import colorette from '@utils/colorette' ; /**
 * A internal logger for using in the verbose renderer mostly.
 */ export class Logger { constructor ( private options ? ) { } public fail ( message ) { message = this . parseMessage ( LogLevels . FAILED , message ) ; console . error ( message ) ; } public skip ( message ) { message = this . parseMessage ( LogLevels . SKIPPED , message ) ; console . info ( message ) ; } public success ( message ) { message = this . parseMessage ( LogLevels . SUCCESS , message ) ; console . log ( message ) ; } public data ( message ) { message = this . parseMessage ( LogLevels . DATA , message ) ; console . info ( message ) ; } public start ( message ) { message = this . parseMessage ( LogLevels . STARTED , message ) ; console . log ( message ) ; } public title ( message ) { message = this . parseMessage ( LogLevels . TITLE , message ) ; console . info ( message ) ; } public retry ( message ) { message = this . parseMessage ( LogLevels . RETRY , message ) ; console . warn ( message ) ; } public rollback ( message ) { message = this . parseMessage ( LogLevels . ROLLBACK , message ) ; console . warn ( message ) ; } protected parseMessage ( level , message ) { let multiLineMessage ; try { multiLineMessage = message . split ( '\n' ) ; } catch { multiLineMessage = [ message ] ; } multiLineMessage = multiLineMessage . map ( ( msg ) => { return this . logColoring ( { level , message : msg } ) ; } ) ; message = multiLineMessage . join ( '\n' ) ; return message ; } protected logColoring ( { level , message } ) { let icon ; let coloring = ( input ) : string => { return input ; } ; switch ( level ) { case LogLevels . FAILED : if ( this . options ?. useIcons ) { coloring = colorette . red ; icon = figures . cross ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . SKIPPED : if ( this . options ?. useIcons ) { coloring = colorette . yellow ; icon = figures . arrowDown ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . SUCCESS : if ( this . options ?. useIcons ) { coloring = colorette . green ; icon = figures . tick ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . DATA : if ( this . options ?. useIcons ) { icon = figures . arrowRight ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . STARTED : if ( this . options ?. useIcons ) { icon = figures . pointer ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . TITLE : if ( this . options ?. useIcons ) { icon = figures . checkboxOn ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . RETRY : if ( this . options ?. useIcons ) { coloring = colorette . yellow ; icon = figures . pointer ; } else { icon = this . wrapInBrackets ( level ) ; } break ; case LogLevels . ROLLBACK : if ( this . options ?. useIcons ) { coloring = colorette . red ; icon = figures . arrowLeft ; } else { icon = this . wrapInBrackets ( level ) ; } break ; } return coloring ( `${ icon } ${ message }` ) ; } private wrapInBrackets ( level ) { return `[${ level }]` ; } }