Error with log4js configuration: must have a prope

2019-07-23 12:38发布

问题:

I am getting Error: Problem with log4js configuration: ({ appenders: [ { type: 'logLevelFilter', level: 'INFO', appenders: { type: 'console' } } ] }) - must have a property "appenders" of type object.

My protractor.conf.js file snippet:

beforeLaunch:function(){
    log4js.configure({
        appenders: 
        [{ type: 'log4js-protractor-appender', 
category: 'protractorLog4js' },
            {
                type: "file",
                filename: './logs/ExecutionLog.log',
                category: 'protractorLog4js'
            }
        ]
    });
  },

I am not sure why i am getting this error even though there is appenders in the conf.

回答1:

log4js-node in version 1.x using format like yours:

appenders:[] // Array

but Object in version 2.x like this:

appenders: {
    cheeseLogs: { type: 'file', filename: 'cheese.log' },
    console: { type: 'console' }
  },
 categories: {
    cheese: { appenders: ['cheeseLogs'], level: 'error' },
    another: { appenders: ['console'], level: 'trace' },
    default: { appenders: ['console', 'cheeseLogs'], level: 'trace' }
}

https://github.com/nomiddlename/log4js-node



回答2:

In the new version your appenders would look like this:

appenders: {
fileLog: { type: 'file', filename: './logs/ExecutionLog.log' },
console: { type: 'log4js-protractor-appender' }
},
categories: {
file: { appenders: ['fileLog'], level: 'error' },
another: { appenders: ['console'], level: 'trace' },
default: { appenders: ['console', 'fileLog'], level: 'trace' }
}


回答3:

Configuration format changed in version 2.x

https://github.com/nomiddlename/log4js-node/issues/500