Python logging to stdout and log file

前端 未结 3 497
一个人的身影
一个人的身影 2021-02-07 00:34

I am fairly new in python and starting to get into the logging module. I would like to have the message logged into a log file and outputting to the console. The code below prin

3条回答
  •  自闭症患者
    2021-02-07 01:15

    You just need to add another handler, like a logging.FileHandler

    fh = logging.FileHandler(r'/path/to/log.txt')
    logger.addHandler(fh)
    

提交回复
热议问题