-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Is there any way to pretty print our JSON logging? #530
Comments
you might be able to just tail log files then pipe it into jq
|
We haven't shipped this in zap, since most Unix tools expect logs to be newline-delimited. Pretty-printing JSON on multiple lines breaks all these tools pretty badly and isn't particularly useful in production either. If you'd like something like this, I suggest either redirecting your application's logs through |
I created https://github.com/maoueh/zap-pretty as a stream CLI tool to pretty print Zap JSON log output. You pipe the stream to it and it will format zap JSON log line into a pretty format. Usage:
|
Cool! This is exactly what I had in mind. Feel free to open a PR and add this to the FAQ if you'd like to publicize this a bit more :) |
@akshayjshah PR sent :) (#676) |
I suppose this still isn't a feature in zap? I saw the |
Outside of We prefer our encoder over the development one. It can be easily instantiated with:
Use the |
Piling in to this issue to state that I've also been working on something to solve this: https://github.com/thessem/zap-prettyconsole I have strayed fairly far from the concept of "pretty JSON" though. |
One can achieve same result using the open-source tool go run . 2>&1 | jq Since it is frequently used |
Can we please stop suggesting IntelliJ and their IDEs for example do not support this. |
I see that @lordzsolt comment mostly downvoted, maybe there's an option to use jq with Intellij and we don't know? Can someone explain if has managed to do it. |
@anatoly-cnvrg I assume the post received mostly downvotes because many Go developers do not use IntelliJ. Just because a tool isn't useful for those who don’t use it doesn't mean it lacks utility for others who find it meets their needs. It might have been more effective to ask, "How can this be accomplished in IntelliJ or in an environment where you cannot install command-line tools or perform post-formatting?" instead. |
Hi. I would like to use zap to achieve structured logging of my CLI app. I like what I'm seeing with sugar.Errorw() , but it would be great if I could pretty print the json so as to look more like
jq
.I found this, but I'm not clear how I could use it for this purpose without changes upstream:
https://github.com/hokaccha/go-prettyjson
Thoughts?
The text was updated successfully, but these errors were encountered: