简体   繁体   中英

Python enable logging for executable during run time

I've created a python module with logging library displaying information. Example of logging output would be...

2016-09-28 02:54:39,089 - INFO - dataServer - Listening for incoming connections...
2016-09-28 02:54:41,089 - INFO - dataServer - Listening for incoming connections...

I've used pyinstaller to generate an executable from the python module. I was wondering if there was a way to enable the logging to display on command prompt when the executable is executed from the command prompt. I know I log to a file but I want to be able to see the logging information in real time.

You must have added a FileHandler to output the content to a file. Similarly to output the content to console add StreamHandler in this way sh = logging.StreamHandler(sys.stdout) and add this handler to logger by logger.addHandler(sh)

Hope this helps, cheers.

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