Shengxin Huang
Shengxin Huang

Reputation: 707

python logging - where has the log file gone

I am trying to add logging to my script,and followed python logging tutorial

example code

import logging

logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')

But I cannot find the example.log file at the directory where the script is in.And as I call os.getcwd(),it returns C:\\users\\eda.No log is there either.

Upvotes: 5

Views: 8526

Answers (1)

Poiz
Poiz

Reputation: 7617

There's nothing wrong with your script. However, be clear that the log file will be saved in the same directory as that from which the script was invoked, since you didn't specify an absolute path.

The screenshot below may help clarify this further:

Tremendously clarifying screen shot

Upvotes: 3

Related Questions