How to log my process my module using python. My script will get Pid and process.
I want to log the output
import psutil
[p.info for p in psutil.process_iter(attrs=['pid', 'name']) if 'firefox' in p.info['name']]
Output > [{'pid': 413, 'name': 'firefox'}]
import logging
logging.basicConfig(level=logging.INFO)
logging.info()
I think there is a simpler solution: the logging module can automatically display the Process ID.
FORMAT = '%(process)d %(message)s'
logging.basicConfig(format=FORMAT)
see docs: https://docs.python.org/3/library/logging.html#logrecord-attributes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With