import { createLogger , format , Logger as IWinstonLogger , transports } from "winston" ; import ILoggerStrategy , { LogLevels } from "./ILoggerStrategy" ; export class implements ILoggerStrategy export default class WinstonLoggerStrategy implements ILoggerStrategy { private readonly winstonLogger : IWinstonLogger ; private readonly consoleTransport ? : transports . ConsoleTransportInstance ; private readonly fileTransport ? : transports . FileTransportInstance ; param { LogLevels } level param { string } logfile memberof public constructor ( level = LogLevels . Debug , logfile ? ) { this . winstonLogger = createLogger ( { format : format . combine ( format . timestamp ( ) , format . printf ( info => `${ info . timestamp } ${ info . contextID } ${ info . level }: ${ info . message }` ) ) , level } ) ; if ( logfile ) { this . fileTransport = new transports . File ( { filename : logfile } ) ; this . winstonLogger . add ( this . fileTransport ) ; } else { this . consoleTransport = new transports . Console ( ) ; this . winstonLogger . add ( this . consoleTransport ) ; } } public log ( level , message , contextID = "\t" ) { this . winstonLogger . log ( { level , message , contextID } ) ; } }