'Log4js Pattern Layout Not Work
I configured this layout:
log4js.configure({
appenders: {
out : {
type :'stdout',
layout: {
type: 'pattern',
pattern:"%d %X{custom} %m %n",
}
}
},
categories: { default: { appenders: ['out'], level: 'debug' } }
});
const logger = log4js.getLogger("default");
logger.level = 'debug';
logger.addContext("custom","EHI");
logger.debug("ciao");
But not custom variable is present in the logger:
[2018-07-11T17:31:31.572] [DEBUG] default - ciao
Solution 1:[1]
I ran the exact same code with version 6.1.2 of log4js module and I got the following output:
2020-04-08T19:05:55.334 EHI ciao
I guess that's the output you were expecting at first. It may be a problem in the version you were running.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
