-
Hey, I'm just setting up logging for my application. I thought that instead of logging to a plain text file, it'll be cool to log into a kind of file that I will be able to open with VisiData as tabular data. I could write a CSV log formatter and use that, but I wonder whether any of you already had that use case and could offer a better suggestion. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The best way is "structured logging", which is just outputting a series of JSON dictionaries, one per event. If you output one per line, that becomes JSONL. In Python I would do it like this:
This is an easy function to use to log at any point, and you can build specialized functions on top of it if you want. |
Beta Was this translation helpful? Give feedback.
That's nice, but then if you'd look at the log of your program as tabular data, it'll be a sparse table since different log messages will use different fields. Also, because you're reinventing logging, your log won't include the logs from all the libraries you call.
I'm now experimenting with using this: