Skip to content

Instantly share code, notes, and snippets.

@birendra-b
Created June 29, 2020 17:23
Show Gist options
  • Save birendra-b/85bc2a55110ad8bc44a3a7bd9147f9e6 to your computer and use it in GitHub Desktop.
Save birendra-b/85bc2a55110ad8bc44a3a7bd9147f9e6 to your computer and use it in GitHub Desktop.
src/shared/Logger.ts
/**
* 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