简体   繁体   中英

activity logging of a python file to a log module

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?

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/

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM