activity logging of a python file to a log module

Viewed 30

I want a python file to run as usual how it runs. But, I want to log the activities going on in the python file in a log file.How can I do it?

1 Answers

It's a bit slow, but the easiest way would probably be:

$ python -m trace --trace your_file.py > trace.log

There's other ways too, but this is a built-in one that's rather detailed using the trace module.

Assuming I understand your question, another option would be to visualize what it's doing which usually is a bit more meaningful. You can do that with a tool called viztracer:

$ viztracer your_module.py

You can then use visualization tools to render the result in a meaningful way, such as https://ui.perfetto.dev/

enter image description here

Related