Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I log to a file with the standard lib "logging" from the ipython qtconsole?

I noticed that I can't log to a file under ipython the way it is possible from the terminal.

If I run the following code from the console the file aaa.log is created but not when I run it from the ipython qtconsole. (I use python 3.2.3 ipython: 0.13.1)

My suspicion is that ipython's own logging feature is in the way. Is there a way to also also use this "standard" logging with ipython? Outputting the logging messages to the qtconsole seems to work however.

import logging

logging.basicConfig(filename='aaa.log', filemode='w', level=logging.DEBUG) 

def my_method():
    logging.debug('This message should go to the log file 2')
    logging.info('So should this')
    logging.warning('And this, too')

if __name__=='__main__':
    my_method()
like image 360
ddd Avatar asked Jan 24 '26 02:01

ddd


1 Answers

I have a similar setup of yours and everything works fine. Are you sure you are searching for the file in the correct directory? You can use the following to check your current directory (the directory where the log file will be written):

>>> import os
>>> os.path.abspath(os.curdir)

Also you can try to specify the full path as filename="/path/to/aaa.log".

like image 109
Salem Avatar answered Jan 25 '26 15:01

Salem