epic_explorer/server/app/utils/logger.ts

32 lines
887 B
TypeScript
Raw Normal View History

2019-07-09 09:22:36 +00:00
import * as winston from 'winston';
export function logger() {
return winston.createLogger({
transports: [
new winston.transports.File({
level: 'info',
filename: './log/all-logs.log',
handleExceptions: true,
maxsize: 5242880, //5MB
maxFiles: 5,
}),
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.align(),
winston.format.printf(info => {
const { timestamp, level, message, ...args } = info;
const ts = timestamp.slice(0, 19).replace('T', ' ');
return `${ts} [${level}]: ${message} ${
Object.keys(args).length ? JSON.stringify(args, null, 2) : ''
}`;
}),
),
}),
],
exitOnError: false,
});
}