import * as winston from 'winston' ; import { AbstractConfigSet } from 'winston/lib/winston/config' ; import { GetTsAutoMockDebugOptions , TsAutoMockDebugOptions , } from '../options/debug' ; import { ConsoleLogger } from './consoleLogger' ; import { FileLogger } from './fileLogger' ; import { ILogger } from './logger.interface' ; function LoggerConfig ( ) { return { levels : { info : 0 , warning : 1 , error : 2 , } , colors : { info : 'green' , warning : 'yellow' , error : 'red' , } , } ; } export function Logger ( service ) { const config = LoggerConfig ( ) ; const winstonLogger = winston . createLogger ( { levels : config . levels , } ) ; winston . addColors ( config . colors ) ; winstonLogger . silent = true ; const options = GetTsAutoMockDebugOptions ( ) ; if ( options ) { winstonLogger . silent = false ; if ( options === 'file' ) { winstonLogger . add ( FileLogger ( ) ) ; } else { winstonLogger . add ( ConsoleLogger ( ) ) ; } } return { info : ( message ) : void => { winstonLogger . info ( `${ service } - ${ message }` ) ; } , warning : ( message ) : void => { winstonLogger . warning ( `${ service } - ${ message }` ) ; } , error : ( message ) : void => { winstonLogger . error ( `${ service } - ${ message }` ) ; } , } ; }