Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Trash: Cookbook Logging

Brian Granger edited this page · 1 revision
Clone this wiki locally

Here is an alternative logging solution that lets you record your sessions in a daily time-stamped log-files.

Add the following lines to your .ipython/ipy_user_conf.py:

from time import strftime

def main():
    try:
        ldir = '/home/$YOUR_USERNAME_HERE/.ipython/'
        filename = os.path.join(ldir, strftime('%Y-%m-%d')+".py")
        notnew = os.path.exists(filename)
        ip.IP.logger.logstart(logfname=filename, logmode='append')
        log_write = ip.IP.logger.log_write
        if notnew:
            log_write("# =================================")
        else:
           log_write("#!/usr/bin/env python \n# %s.py \n"
                     "# IPython automatic logging file"
                     % strftime('%Y-%m-%d'))
        log_write("# %s \n# =================================" %
                  strftime('%H:%M'))
        print " Logging to "+filename
      
    except RuntimeError:
        print " Already logging to "+ip.IP.logger.logfname
Something went wrong with that request. Please try again.