I'm using node-log4js. (it's log4JS, not log4J!) I thought of the loggers 'categories' to be just like the Strings you put in Log4J into the constructor of a logger (normally you put your fqn class name there), so that log4j can put logged things to the right location.
I got the following config:
{
"appenders": [
{
"type": "console",
},
{
"type": "file",
"absolute": true,
"filename": "/tmp/app.log",
"maxLogSize": 20480,
"backups": 10
},
{
"type": "console",
"category": "app.access"
}
]
}
The desired behaviour would be that all "app.access" stuff only goes to the last appender (which is, at the moment, the console, too, but could change in future). At the moment, all loggings with the category 'app.access' will be logged twice to console and once to file.
Is there a way to give those other two appenders a "all but app.access"-category? How?
Thank you very much in advance
I had a similar requirement. I wanted to exclude a bunch of categories from the console logger.
I wrote something based on the logLevelFilter, which I called categoryFilter.
categoryFilter.js:
"use strict";
var log4js = require('log4js');
function categoryFilter (excludeCategories, appender) {
return function(logEvent) {
if (excludeCategories.every(function(x){return (x!=logEvent.category);})) {
appender(logEvent);
}
};
}
function configure(config) {
log4js.loadAppender(config.appender.type);
var appender = log4js.appenderMakers[config.appender.type](config.appender);
return categoryFilter(config.exclude, appender);
}
exports.appender = categoryFilter;
exports.configure = configure;
To use it, I have this snippet near the beginning of my app:
var log4js = require('log4js');
log4js.loadAppender('categoryFilter',require('./src/categoryFilter'));
log4js.configure('log4js-conf.js');
My configuration file has the following:
{
"appenders": [
{
"type": "file",
"filename": "logs/logfile.log",
"maxLogSize": 20480,
"backups": 3
},
{
"type": "categoryFilter",
"exclude":["results"],
"appender":{
"type": "console"
}
},
],
"replaceConsole":true
}
I'd be interested in your thoughts.