Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression with levelKey handling in version 10 #456

Closed
paulish opened this issue Sep 8, 2023 · 2 comments · Fixed by #538
Closed

Regression with levelKey handling in version 10 #456

paulish opened this issue Sep 8, 2023 · 2 comments · Fixed by #538

Comments

@paulish
Copy link

paulish commented Sep 8, 2023

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'
});

The example output is
image

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
image

Ths time it has no colored INFO and DEBUG levels.

@mcollina
Copy link
Member

mcollina commented Sep 8, 2023

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@eliw00d
Copy link
Contributor

eliw00d commented Nov 4, 2024

@mcollina I have created a PR with a fix for this.

mcollina pushed a commit that referenced this issue Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants