2 回答
TA贡献1833条经验 获得超4个赞
希望以下解决方案对您有用。
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, printf} = format;
const transport = new transports.Console({
exitOnError: false,
format: combine(
...(environment === 'dev' ? [format.colorize()] : []),
timestamp(),
printf(info => `${info.timestamp} [${info.level}]: ${info.message}`)
),
colorize: true,
level: 'debug',
});
const myFormat = printf(({ level, message, timestamp }) => {
return `${timestamp} ${level}: ${message}`;
});
const logger = createLogger({
format: combine(timestamp(), appendTimestamp({ tz: 'Add your timezone'}), myFormat),
transports: [transport],
exceptionHandlers: [
new transports.File({
filename: 'FILE_NAME.log'
}),
],
});
添加回答
举报