Python does not create log file
Question: 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](https://docs.python.org/2/howto/logging.html#logging-to-a-file). 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`.


Answer: The reason for your unexpected result is that you are using something on top
of Python (looks like IPython) which configures the root logger itself. As per
[the documentation for
basicConfig()](https://docs.python.org/2/library/logging.html#logging.basicConfig),

> This function does nothing if the root logger already has handlers
> configured for it.

What you get with just Python is something like this:

    
    
    C:\temp>python
    ActivePython 2.6.1.1 (ActiveState Software Inc.) based on
    Python 2.6.1 (r261:67515, Dec  5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import logging
    >>> logging.basicConfig(filename='example.log', level=logging.DEBUG)
    >>> logging.debug('This message should go to the log file')
    >>> logging.info('And so should this')
    >>> logging.warning('And this, too')
    >>> ^Z
    
    C:\temp>type example.log
    DEBUG:root:This message should go to the log file
    INFO:root:And so should this
    WARNING:root:And this, too
    

