Logging basicConfig not creating log file when i run in pycharm?

前端 未结 6 510
醉话见心
醉话见心 2020-12-29 03:34

When i run below code in terminal its create a log file

import logging 
logging.basicConfig(filename=\'ramexample.log\',level=logging.DEBUG)
logging.debug(\         


        
6条回答
  •  有刺的猬
    2020-12-29 04:22

    The answer why this error happens is this:

    The call to basicConfig() should come before any calls to debug(), info() etc.

    If you do so the basicConfig can not create and write a new file. Here I called logging.info() right before logging.basicConfig().

    Don't:

    import logging
    logging.info("root") # call to info too early
    logging.basicConfig(filename="rec/test.log", level=logging.DEBUG) # no file created
    

提交回复
热议问题