import tl = require ( 'azure-pipelines-task-lib/task' ) ; import { LoggingLevel , MessageType } from '../enums' ; export class Logger { breakOnWarning : boolean ; logLevel : LoggingLevel ; constructor ( breakOnWarning , logLevel ) { this . breakOnWarning = breakOnWarning ; this . logLevel = logLevel ; } info ( message ) { this . log ( MessageType . Info , message ) ; } debug ( message ) { this . log ( MessageType . Debug , message ) ; } warning ( message ) { this . log ( MessageType . Warning , message ) ; } error ( message ) { this . log ( MessageType . Error , message ) ; } success ( message ) { this . log ( MessageType . Success , message ) ; } private log ( type , message ) { switch ( type ) { case MessageType . Info : { if ( this . logLevel !== LoggingLevel . Off ) { console . log ( message ) ; } } break ; case MessageType . Debug : { if ( this . logLevel === LoggingLevel . Verbose ) { console . log ( message ) ; tl . debug ( message ) ; } } break ; case MessageType . Warning : this . breakOnWarning ? tl . setResult ( tl . TaskResult . Failed , message ) : tl . warning ( message ) ; break ; case MessageType . Error : tl . setResult ( tl . TaskResult . Failed , message ) ; break ; case MessageType . Success : tl . setResult ( tl . TaskResult . Succeeded , message ) ; break ; } } }