var log4js = require('log4js');
log4js.configure({
appenders: [
{ type: 'console' },
{
type: 'dateFile',
filename: 'logs/pattern_yyyy-MM-dd.log',
//filename: "blah.log",
pattern: "-yyyy-MM-dd",
maxLogSize: 1024,
// "pattern": "-yyyy-MM-dd",
alwaysIncludePattern: false,
backups: 4,
category: 'normal'
},
],
replaceConsole: true
});
不能生成以日期命名的日志
6 回复
我在项目中也遇到了同样的问题,匹配到秒或者分的pattern可以自动生成新文件,可是,我改成yyyy-mm-dd的格式后,第二天启动项目,依然在老文件中追加日志,不会自动生成新的日志文件.
同样 求助!!
将alwaysIncludePattern修改为true就可以了,生成格式如access.log-2014-06-05, 看起来有点别扭,至于生成access_2014-06-05.log格式的文件暂未找到方法 log4js.configure({ appenders: [ { type: 'dateFile’, absolute: true, filename: __dirname + './logs/access.log’, maxLogSize: 1024 * 1024, backup: 3, pattern: "-yyyy-MM-dd", alwaysIncludePattern: true, category: ‘normal’ } ], replaceConsole: true });