I am trying to implement some logging for recording messages. I am getting some weird behavior so I tried to find a minimal example, which I found here. When I just copy the easy example described there into my interpreter the file is not created as you can see here:
In [1]: 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')
WARNING:root:And this, too
In [2]: ls example.log
File not found
Can anybody help me to understand what I am doing wrong? Thanks...
EDIT: changed the output after the second input to English and removed the unnecessary parts. The only important thing is that Python does not create the file example.log
.
example.log
? – Cannoneerexample.log
is a file that you must create. Take a look at the Pyhton logging HOWTO (here for Python 2) to see some example. The logging library is not supposed to create it. – Cannoneerlogging.basicConfig
withlogging.config.fileConfig
. – Cannoneer