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

A "nestedKeyName: {}" is always added to the log and displayed by pretty even if there is nothing to nest #1166

Closed
frzsombor opened this issue Oct 17, 2021 · 8 comments · Fixed by #1198

Comments

@frzsombor
Copy link
Contributor

frzsombor commented Oct 17, 2021

If I set the nestedKey: payload option, the nested key is always added to the log and pino-pretty also displays it every time, even if I try to log a simple string (and if I can remember correctly, this was not the case with v6).

A simple logger.info('info'); makes pino-pretty (with base: undefined, timestamp: pino.stdTimeFunctions.isoTime options) show the following:

[2021-10-17T17:52:12.208Z] INFO: info
    payload: {}

My current workaround:
Right now I'm using the following hook method to achieve similar results as v6 (only wrap object if necessary):

hooks: {
    logMethod (inputArgs, method, level) {
        if (typeof inputArgs[0] !== 'string' && !(inputArgs[0] instanceof Error)) {
            return method.apply(this, [ { object: inputArgs[0] } ]);
        }
        return method.apply(this, inputArgs);
    }
},
@mcollina
Copy link
Member

This looks like a bug. Would you like to send a PR to fix it?

@frzsombor
Copy link
Contributor Author

I actually tried to fix this in the code too, but I could not decide if it is a problem in proto.js here or I should simply add an additional check in tools.js here. That's all I've found.

@mcollina
Copy link
Member

probably in the line with mixin defined.

If that's the case this ha not been introduced in v7, what's the latesr version this was working for you?

@frzsombor
Copy link
Contributor Author

frzsombor commented Oct 18, 2021

For me, it definitely looks like a v7 related change/bug.
Simple test:

const logger = require('pino')({nestedKey:'nest'});
logger.info({asd:'1'});
logger.info('hello');

pino v6.13.3 results:

{"level":30,"time":1634576867070,"pid":41448,"hostname":"x","nest":{"asd":"1"}}
{"level":30,"time":1634576867071,"pid":41448,"hostname":"x","msg":"hello"}

pino v7.0.2 results:

{"level":30,"time":1634577116365,"pid":41717,"hostname":"x","nest":{"asd":"1"}}
{"level":30,"time":1634577116365,"pid":41717,"hostname":"x","nest":{},"msg":"hello"}  <- 'nest' added in v7

@mcollina
Copy link
Member

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

@frzsombor
Copy link
Contributor Author

I would be happy to help, but I think this task might require a deeper understanding of the codebase that I currently have in this project.

@simoneb
Copy link
Contributor

simoneb commented Oct 21, 2021

A git bisect shows that this behavior was introduced in #885

@github-actions
Copy link

github-actions bot commented Feb 2, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants