1

I am trying to find the equivalent function of idl's journal in python (or ipython). I know ipython has the %logstart function but that only record the input/output in ipython, so if I run my script and it asks me to input values, these don't get into the log. To make it clear here is my terminal when I run the EELTnoM6.py script:

In [11]: run EELTnoM6

################################################################
##             STOKES vector after the system                 ##
################################################################ 

== Demodulation matrix ==
Automatic:                A
ZIMPOL/EELT:              Z
EELT IF                   Eif
Custom                    C
Demodulation matrix?: C
Efficiency of the detector?: 1.
Demodulation matrix? (e.g. [ [1.,0.],[0.,1.] ]): [[1/6.,1/6.,1/6.,1/6.,1/6.,1/6.],     [0.5,-0.5,0.,0.,0.,0.],[0.,0.,-0.5,0.5,0.,0.],[0.,0.,0.,0.,-0.5,0.5]]
ModelStokesMeasurement time =  65.6509261131
Simulation time =  151.731481075

and here is what I get in the log:

# IPython log file
%logstart -o -r EELTnoM6_log rotate
ls
%logstop
run EELTnoM6
%logoff

I would like to store in the log the inputs that I give when the script asks, i.e.

Demodulation matrix?: C 
Efficiency of the detector?: 1.
Demodulation matrix? (e.g. [ [1.,0.],[0.,1.] ]): [[1/6.,1/6.,1/6.,1/6.,1/6.,1/6.],[0.5,-0.5,0.,0.,0.,0.],[0.,0.,-0.5,0.5,0.,0.],[0.,0.,0.,0.,-0.5,0.5]]

So C, 1. and the matrix to be able to run it again with the same values. This is extremely easy in IDl so I was very surprised when I couldn't find the same for ipython...

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
mjo
  • 133
  • 1
  • 1
  • 7

1 Answers1

0

I think you just want to use the logging function. It is pretty awesome, and handles multi-threads really well.

import logging

log_file = 'journal.log' # Specify path to your log file

log_format = '[%(asctime)s] %(levelname)s: %(message)s'  # How the output is displayed
log_date_fmt = '%m/%d/%Y %I:%M:%S %p'  # How the asctime is displayed

logging.basicConfig(filename=log_file, level='DEBUG', filemode='w', format=log_format, datefmt=log_date_fmt)  # Fire up the logger
logging.info('Logger initialized')  # There are DEBUG, INFO, WARNING, ERROR levels

def journal(msg):
    ans = raw_input(msg)  # Get your user input
    logging.debug(msg + ans)  # Choosing to put it as DEBUG category
    return ans

ans = journal('Demodulation matrix?: ')  # From your example

Gives the output (contained in ./journal.log:

[09/17/2014 04:11:49 PM] INFO: Logger initialized

[09/17/2014 04:11:51PM] DEBUG: Demodulation matrix?: C

jakebrinkmann
  • 704
  • 9
  • 23