redirect prints to log file

前端 未结 8 1655
萌比男神i
萌比男神i 2020-12-02 09:05

Okay. I have completed my first python program.It has around 1000 lines of code. During development I placed plenty of print statements before running a command

8条回答
  •  被撕碎了的回忆
    2020-12-02 09:46

    Just a note about append vs write mode. Change filemode to "w" if you would like it to replace log file. I also had to comment out the stream. Then using logging.info() was outputting to file specified.

    if __name__ == '__main__':
        LOG_FORMAT = '%(asctime)s:%(levelname)s ==> %(message)s'
        logging.basicConfig(
            level=logging.INFO,
            filename="logfile",
            filemode="w",
            format=LOG_FORMAT
            #stream=sys.stdout
        )
    

提交回复
热议问题