Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format PyCharm's consle output for json logs

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.

like image 941
Guy Grin Avatar asked Jun 01 '26 05:06

Guy Grin


1 Answers

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.

like image 128
ItayBenHaim Avatar answered Jun 02 '26 19:06

ItayBenHaim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!