Created
June 29, 2020 17:23
-
-
Save birendra-b/85bc2a55110ad8bc44a3a7bd9147f9e6 to your computer and use it in GitHub Desktop.
src/shared/Logger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Setup the winston logger. | |
* | |
* Documentation: https://github.com/winstonjs/winston | |
*/ | |
import { createLogger, format, transports } from 'winston'; | |
// Import Functions | |
const { File, Console } = transports; | |
// Init Logger | |
const logger = createLogger({ | |
level: 'info', | |
}); | |
const errorStackFormat = format((info) => { | |
if (info.stack) { | |
// tslint:disable-next-line:no-console | |
console.log(info.stack); | |
return false; | |
} | |
return info; | |
}); | |
const consoleTransport = new Console({ | |
format: format.combine( | |
format.colorize(), | |
format.simple(), | |
errorStackFormat(), | |
), | |
}); | |
logger.add(consoleTransport); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment