log4js-json-layout
log4js-json-layout copied to clipboard
include not working?
I must be missing something. I can only include startTime, categoryName, level, and data in my json output.
It appears to be because the formatter code selects the fields from output instead of data:
// Only include fields specified in 'include' field
// if field is specified
if (config.include && config.include.length) {
const newOutput = {};
_.forEach(config.include, (key) => {
if (_.has(output, key)) {
newOutput[key] = output[key];
}
});
return newOutput;
}
data is set earlier as a clone of the formatter input:
function formatter(raw) {
const data = _.clone(raw);
...
and output specifically only selects a few fields:
const output = {
startTime: data.startTime,
categoryName: data.categoryName,
level: data.level.levelStr,
};
It would appear that this bit of code at line 105:
if (_.has(output, key)) {
newOutput[key] = output[key];
}
should be:
if (_.has(data, key)) {
newOutput[key] = data[key];
}
Am I missing something? I assume I'm doing something wrong...
This fix wouldn't be entirely right; it butchers the level field. A more thoughtful fix is needed, unless I'm just not using this right...
Feel free to submit a pull request and I'll review it.