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

前端 未结 6 584
醉话见心
醉话见心 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:12

    Maximas is right. File path is relative to execution environment. However instead of writing down the absolute path you could try the dynamic path resolution approach:

    filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ram.log')
    logging.basicConfig(filename=filename, level=logging.DEBUG)
    

    This assumes that ram.log resides in the same directory with the one that contains the above code (that's why __file__ is used for).

提交回复
热议问题