我该如何改变这个log4js

时间:2017-07-26 21:42:47

标签: javascript node.js log4js-node

我应该如何改变这一点:

log4js.configure({
    appenders: [
        { type: 'console' },
        { type: 'file', filename: 'logs/site.log' }
    ]
});

因为我收到了以下错误:

Error: Problem with log4js configuration: ({ appenders:
   [ { type: 'console' },
     { type: 'file', filename: 'logs/site.log' } ] }) - must have a property "appenders" of type object.

1 个答案:

答案 0 :(得分:0)

appenders应该是一个普通对象,将每个appender作为给定名称(键)的值:

log4js.configure({
    appenders: {
        con: { type: 'console' },
        fil: { type: 'file', filename: 'logs/site.log' }
    }
});

然后按名称引用appender,如下所示:

log4js.getLogger('con');

另请参阅documentation