Format PyCharm's consle output for json logs
Asked Answered
I

2

8

I'm working on an app whose logs are formatted as JSON with a structure similar to

{"level": "INFO", "lineno": 85, "timestamp": "2020-01-01", "message": "Some message"}

This format works great in production where the logs are sent to ELK, but as the logs get more complicated it's harder understand them in PyCharm.

I'm looking for a way to format the output of the console (so I don't have to change the format of the logs in the code) to something more readable e.g.

2020-01-01 INFO 85 Some message

Looking for some solution I found this option that uses bunyan and also a suggestion to use GrepConsole. I didn't manage to make either of them work.

The bunyan solution simply didn't work. The logs kept showing as JSON and GrepConsole is great for filtering or highlighting some text, but not for manipulations.

Any ideas would be greatly appreciated.

Inquire answered 22/9, 2020 at 23:13 Comment(2)
Isn't it easier to add a DEBUG flag to your code or your environment and format the output before sending it to console if running in debug mode?Aldwin
That's a good option but the logging is an external package I don't own. I would have to encapsulate it and replace the usages across all of the app. I'll do it if there aren't any better optionsInquire
B
1

Since python3.11, the new stack trace gets even more complex when using json-formatter.

However, Pycharm has added a small "soft-wrap" option which will expand the json to full size:

This: enter image description here

Turns into this: enter image description here

Hope it can help.

Blessing answered 16/5, 2023 at 5:45 Comment(0)
C
0

Recently tried this plugin : pretty-json-log. It parses the json log along with color highlight

pretty json log plugin ouptut

Carpentaria answered 16/8, 2024 at 9:14 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.