How to output to the console and file?

前端 未结 8 1189
青春惊慌失措
青春惊慌失措 2020-11-30 02:54

I\'m trying to find out a way in python to redirect the script execution log to a file as well as stdout in a pythonic way. Is there any easy way of achieving t

8条回答
  •  -上瘾入骨i
    2020-11-30 03:25

    I just want to build upon Serpens answer and add the line:

    logger.setLevel('DEBUG')
    

    This will allow you to chose what level of message gets logged.

    For example in Serpens example,

    logger.info('Info message')
    

    Will not get recorded as it defaults to only recording Warnings and above.

    More about levels used can be read about here

提交回复
热议问题