CalMerger/src/logger.js

24 lines
648 B
JavaScript

import { createLogger, format, transports } from 'winston';
const { combine, timestamp, printf, colorize } = format;
// Define custom log format
const logFormat = printf(({ level, message, timestamp }) => {
return `[${timestamp}] ${level}: ${message}`;
});
//create logger
const logger = createLogger({
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
format: combine(
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
colorize(),
logFormat
),
transports: [
new transports.Console(),
new transports.File({ filename: 'logs/calmerge.log' })
]
});
export default logger;