node.js - 关于log4js在多进程下丢消息的问题
PHP中文网
PHP中文网 2017-04-17 11:33:45
0
1
263

log4js的用户大家一起来交流一下使用经验,反正我在使用的时候出现了问题。如果使用单进程,这个问题不会被暴漏,但是如果用多进程,问题就来了。首先看我的log4js的配置信息:

log4js.configure({
    appenders: [
        { type: 'console' },
        { type: 'dateFile',filename:debugFile,'pattern':'-yyyy-MM-dd',category: 'debug'}, 
        { type: 'dateFile',filename:traceFile,'pattern':'-yyyy-MM-dd',category: 'trace'},
        { type: 'file',filename:errorFile,maxLogSize:102400000,backups:10,category: 'error'}
    ],
    replaceConsole : true
});

我的访问日志是同时打印到控制台和trace日志的,如果使用多进程,我发现有一些日志记录,仅仅在控制台日志中出现,但是在trace日志文件中却没有。同样的情况在debug中也是存在的。
我的log4js版本0.6.21

PHP中文网
PHP中文网

认证0级讲师

répondre à tous(1)
左手右手慢动作

应该是并发写文件,导致appendfile的内容一定几率覆盖,stackoverflow的解决办法是将worker的std定向到master,这样只有master一个进程负责log。

参考:http://stackoverflow.com/questions/18841333/when-use-the-cluster-and-winston-in-nodejs-the-logs-maxsize-does-not-work

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!