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

How to render \ns in arbitrary data properties #426

Open
egargan opened this issue May 9, 2023 · 9 comments
Open

How to render \ns in arbitrary data properties #426

egargan opened this issue May 9, 2023 · 9 comments

Comments

@egargan
Copy link

egargan commented May 9, 2023

I'd like to be able to display just the stack property when logging errors, instead of giving the whole error to Pino when logging them.

In an app of mine, I like to log out only an error's stack property, instead of just giving the entire error to Pino to display. When I do this, the stack is printed in a signle line, without rendering its \ns.

image

If I hand the whole error to Pino, i.e. logger.error(err), the stack is printed "prettily", broken across multiple lines.

image

How do I tell Pino to render my stack property's newlines? I've looked through the docs for pino-pretty's config options, but I can't find anything there that solves my problem.

@jsumners
Copy link
Member

logger.error(err) gets serialized by the error serializer attached to the Pino instance. If you want a different serialization, you need to provide a serializer that does what you want.

@mcollina
Copy link
Member

@jsumners I don't think that's the case.

This is currently not possible in pino-pretty. I'm not even sure how it could be implemented reliably, but it would be good PR there.

@jsumners
Copy link
Member

The implementation here recognizes serialized errors from Pino.

@mcollina
Copy link
Member

Yes, exactly. This is not a serialized error.

@egargan
Copy link
Author

egargan commented May 16, 2023

Yep you've got it @mcollina, I should have been clearer.

For that first second screencap I'm doing logger.error({ stack: error.stack }). I'd like this output to be nice and newliend and indented, like it is when I just do logger.error({ error }).

@mcollina if it's implemented for the error serializer, surely it's possible? Would it just be a case of extracting the code in this error serializer that renders newlines, and making it available as a config option?

@mcollina
Copy link
Member

The code is very specific for errors: https://github.com/pinojs/pino-pretty/blob/master/lib/utils.js#L180.

A PR would be awesome.

@egargan
Copy link
Author

egargan commented May 17, 2023

OK I'll have a crack when I find some time!

Still a bit unsure why the \ns aren't being rendered for me though, when it seems like that's all the error serializer uses to produce multi-line output?

https://github.com/pinojs/pino-pretty/blob/master/lib/utils.js#L152

@notmedia
Copy link

@egargan Hi, did you find the solution?

@johanbook
Copy link

I would also find this useful. I am an project where we use a custom serializer for errors and the stack trace is serialized as a property stackTrace which then prints as stated in post description

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

No branches or pull requests

5 participants