Regression with levelKey handling in version 10
paulish opened this issue · comments
When pino-pretty is used together with elastic formatting the logging level has log.level
key in the log object. I found no way to make pino-pretty work correctly with this level key.
In version 9 pino-pretty allowed dot in key names without escaping while in version 10 we need to escape it with slashes.
This would be ok but this escaping breaks excluding this key from the message string.
Example (uncomment levelKey with/without escaping to see different havaviours):
const pino = require('pino');
const pretty = require('pino-pretty');
const ecsFormat = require('@elastic/ecs-pino-format');
const options = ecsFormat({});
options.level = 'debug';
const logger = pino(options, pretty({
colorize: true,
singleLine: true,
levelKey: 'log\\.level', // if levelKey dot is escaped then log.level appears at the console output
// levelKey: 'log.level', // if levelKey dot is not escaped then level is not showing between message
timestampKey: '@timestamp',
messageKey: 'message',
ignore: 'service,process,host,ecs'
}));
logger.info('Starting');
logger.debug({
extraParam: '123',
message: 'hello hello'
});
As you can see the output contains unwanted "log.level":"info"
and "log.level":"debug"
.
If I remove dot escaping then the output changes to
Ths time it has no colored INFO
and DEBUG
levels.
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.