pm2和log4js不兼容
本文介绍了pm2和log4js不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
不知道大家有没有将pm2和log4js结合在一起使用的,我用了一下,发现日志无法在控制台打印了。即使调用console.log也看不到输出。
log4js.configure({
appenders: {
console:{type:'console'},
error:{type: 'file', filename: errorFile, maxLogSize: 1024000, backups: 10}
},
categories: { default: { appenders: ['console','error'], level: 'trace' } },
replaceConsole: true
});
解决方案
log4js 2.x开始,在pm2中使用log4js必须在configure中指定pm2属性为true,否则log4js会失效。
log4js.configure({
appenders: {
console:{type:'console'},
error:{type: 'file', filename: errorFile, maxLogSize: 1024000, backups: 10}
},
categories: { default: { appenders: ['console','error'], level: 'trace' } },
pm2: true,
replaceConsole: true
});
另外replaceConsole这个参数貌似也去掉了,console.log不会被log4js格式化了。
这篇关于pm2和log4js不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文