[IPython-user] ask help for "Effective logging"
Ville Vainio
vivainio at gmail.com
Wed Jan 18 14:16:51 CST 2006
I'll look into this, apparently post_config_initialization is "too
late" for logging to work properly.
On 1/18/06, Stephen Walton <stephen.walton at csun.edu> wrote:
> Fernando Perez wrote:
>
> >~/.ipython/ipythonrc-autolog
> >
> >which would contain:
> >
> >include ipythonrc
> >logfile '' # cancel earlier logfile invocation
> >execute import time
> >execute __cmd = 'PUT_SOME_PATH_YOU_WANT_HERE-%s.log rotate'
> >execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
> >
> >
> >Then, you'd simply call ipython using this profile as
> >
> >ipython -p autolog
> >
> >
> This looked so interesting that I decided to try it. Unfortunately it
> didn't work for me. I changed PUT_SOME_PATH_YOU_WANT_HERE to
> /home/swalton/test/log, assuming files would be named
> /home/swalton/test/log-%Y-%m-%d.log or something similar. But "ipython
> -p autolog" dies with the attached crash log.
>
> Steve
>
>
>
> ***************************************************************************
>
> IPython post-mortem report
>
> IPython version: 0.7.0
>
> SVN revision : $Revision: 1000 $
>
> Platform info : os.name -> posix, sys.platform -> linux2
>
> ***************************************************************************
>
> Current user configuration structure:
>
> {'Version': 0,
> 'alias': [''],
> 'args': [],
> 'autocall': 1,
> 'autoedit_syntax': 1,
> 'autoindent': 1,
> 'automagic': 1,
> 'banner': 1,
> 'c': '',
> 'cache_size': 1000,
> 'classic': 0,
> 'color_info': 1,
> 'colors': 'LightBG',
> 'confirm_exit': 1,
> 'debug': 0,
> 'deep_reload': 0,
> 'editor': '0',
> 'execfile': [],
> 'execute': ['',
> 'import time',
> "__cmd = '/home/swalton/test/foo-%s.log rotate'",
> "__IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))"],
> 'gthread': 0,
> 'help': 0,
> 'ignore': 0,
> 'import_all': [],
> 'import_mod': [],
> 'import_some': [[]],
> 'include': ['ipythonrc'],
> 'ipythondir': '/home/swalton/.ipython',
> 'log': 0,
> 'logfile': "'' # cancel earlier logfile invocation",
> 'logplay': '',
> 'magic_docstrings': 0,
> 'messages': 1,
> 'multi_line_specials': 1,
> 'nosep': 0,
> 'opts': Struct({'profile': 'autolog'}),
> 'pdb': 0,
> 'pprint': 1,
> 'profile': 'autolog',
> 'prompt_in1': 'In [\\#]:',
> 'prompt_in2': ' .\\D.:',
> 'prompt_out': 'Out[\\#]:',
> 'prompts_pad_left': 1,
> 'pylab': 0,
> 'qthread': 0,
> 'quick': 0,
> 'rcfile': 'ipythonrc',
> 'readline': 1,
> 'readline_merge_completions': 1,
> 'readline_omit__names': 0,
> 'readline_parse_and_bind': ['tab: complete',
> '"\\C-l": possible-completions',
> 'set show-all-if-ambiguous on',
> '"\\C-o": tab-insert',
> '"\\M-i": " "',
> '"\\M-o": "\\d\\d\\d\\d"',
> '"\\M-I": "\\d\\d\\d\\d"',
> '"\\C-r": reverse-search-history',
> '"\\C-s": forward-search-history',
> '"\\C-p": history-search-backward',
> '"\\C-n": history-search-forward'],
> 'readline_remove_delims': '\'"[]{}-/~',
> 'screen_length': 0,
> 'separate_in': '\\n',
> 'separate_out': '0',
> 'separate_out2': '0',
> 'system_verbose': 0,
> 'tk': 0,
> 'upgrade': 0,
> 'wildcards_case_sensitive': 1,
> 'wthread': 0,
> 'wxversion': '0',
> 'xmode': 'Context'}
>
> ***************************************************************************
>
> Crash traceback:
>
> ---------------------------------------------------------------------------
> exceptions.AttributeError Python 2.4.1: /usr/bin/python
> Wed Jan 18 11:38:46 2006
> A problem occured executing Python code. Here is the sequence of function
> calls leading up to the error, with the most recent (innermost) call last.
>
> /usr/bin/ipython
> 13
> 14 [or simply IPython.Shell.IPShell().mainloop(1) ]
> 15
> 16 and IPython will be your working environment when you start python. The final
> 17 sys.exit() call will make python exit transparently when IPython finishes, so
> 18 you don't have an extra prompt to get out of.
> 19
> 20 This is probably useful to developers who manage multiple Python versions and
> 21 don't want to have correspondingly multiple IPython versions. Note that in
> 22 this mode, there is no way to pass IPython any command-line options, as those
> 23 are trapped first by Python itself.
> 24 """
> 25
> 26 import IPython
> 27
> ---> 28 IPython.Shell.start().mainloop()
> IPython.Shell.start.mainloop = undefined
> 29
> 30
> 31
> 32
> 33
> 34
> 35
> 36
> 37
> 38
> 39
> 40
> 41
> 42
> 43
>
> /usr/lib/python2.4/site-packages/IPython/Shell.py in start()
> 913 if arg2.endswith('-tk'):
> 914 USE_TK = True
> 915 arg1 = argv[1]
> 916 if arg1.endswith('-gthread'):
> 917 shell = IPShellGTK
> 918 elif arg1.endswith( '-qthread' ):
> 919 shell = IPShellQt
> 920 elif arg1.endswith('-wthread'):
> 921 shell = IPShellWX
> 922 elif arg1.endswith('-pylab'):
> 923 shell = _matplotlib_shell_class()
> 924 else:
> 925 shell = IPShell
> 926 else:
> 927 shell = IPShell
> --> 928 return shell()
> shell = <class IPython.Shell.IPShell at 0x4032adac>
> 929
> 930 # Some aliases for backwards compatibility
> 931 IPythonShell = IPShell
> 932 IPythonShellEmbed = IPShellEmbed
> 933 #************************ End of file <Shell.py> ***************************
> 934
> 935
> 936
> 937
> 938
> 939
> 940
> 941
> 942
> 943
>
> /usr/lib/python2.4/site-packages/IPython/Shell.py in __init__(self=<IPython.Shell.IPShell instance>, argv=None, user_ns=None, user_global_ns=None, debug=1, shell_class=<class 'IPython.iplib.InteractiveShell'>)
> 38
> 39 # global flag to turn on/off Tk support.
> 40 USE_TK = False
> 41
> 42 #-----------------------------------------------------------------------------
> 43 # This class is trivial now, but I want to have it in to publish a clean
> 44 # interface. Later when the internals are reorganized, code that uses this
> 45 # shouldn't have to change.
> 46
> 47 class IPShell:
> 48 """Create an IPython instance."""
> 49
> 50 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
> 51 debug=1,shell_class=InteractiveShell):
> 52 self.IP = make_IPython(argv,user_ns=user_ns,user_global_ns=user_global_ns,
> ---> 53 debug=debug,shell_class=shell_class)
> debug = 1
> shell_class = <class 'IPython.iplib.InteractiveShell'>
> 54
> 55 def mainloop(self,sys_exit=0,banner=None):
> 56 self.IP.mainloop(banner)
> 57 if sys_exit:
> 58 sys.exit()
> 59
> 60 #-----------------------------------------------------------------------------
> 61 class IPShellEmbed:
> 62 """Allow embedding an IPython shell into a running program.
> 63
> 64 Instances of this class are callable, with the __call__ method being an
> 65 alias to the embed() method of an InteractiveShell instance.
> 66
> 67 Usage (see also the example-embed.py file for a running example):
> 68
>
> /usr/lib/python2.4/site-packages/IPython/ipmaker.py in make_IPython(argv=['/usr/bin/ipython', '-p', 'autolog'], user_ns=None, user_global_ns=None, debug=1, rc_override=None, shell_class=<class 'IPython.iplib.InteractiveShell'>, embedded=False, **kw={})
> 500 if IP_rc.profile:
> 501 histfname = 'history-%s' % IP_rc.profile
> 502 else:
> 503 histfname = 'history'
> 504 IP.histfile = os.path.join(opts_all.ipythondir,histfname)
> 505
> 506 # update exception handlers with rc file status
> 507 otrap.trap_out() # I don't want these messages ever.
> 508 IP.magic_xmode(IP_rc.xmode)
> 509 otrap.release_out()
> 510
> 511 # activate logging if requested and not reloading a log
> 512 if IP_rc.logplay:
> 513 IP.magic_logstart(IP_rc.logplay + ' append')
> 514 elif IP_rc.logfile:
> --> 515 IP.magic_logstart(IP_rc.logfile)
> IP.magic_logstart = <bound method InteractiveShell.magic_logstart of <IPython.iplib.InteractiveShell object at 0x400647ac>>
> IP_rc.logfile = "'' # cancel earlier logfile invocation"
> 516 elif IP_rc.log:
> 517 IP.magic_logstart()
> 518
> 519 # find user editor so that it we don't have to look it up constantly
> 520 if IP_rc.editor.strip()=='0':
> 521 try:
> 522 ed = os.environ['EDITOR']
> 523 except KeyError:
> 524 if os.name == 'posix':
> 525 ed = 'vi' # the only one guaranteed to be there!
> 526 else:
> 527 ed = 'notepad' # same in Windows!
> 528 IP_rc.editor = ed
> 529
> 530 # Keep track of whether this is an embedded instance or not (useful for
>
> /usr/lib/python2.4/site-packages/IPython/Magic.py in magic_logstart(self=<IPython.iplib.InteractiveShell object>, parameter_s="'' # cancel earlier logfile invocation")
> 971 Python code.
> 972
> 973 Since this marker is always the same, filtering only the output from
> 974 a log is very easy, using for example a simple awk call:
> 975
> 976 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
> 977
> 978 -t: put timestamps before each input line logged (these are put in
> 979 comments)."""
> 980
> 981 opts,par = self.parse_options(parameter_s,'ot')
> 982 log_output = 'o' in opts
> 983 timestamp = 't' in opts
> 984
> 985 rc = self.shell.rc
> --> 986 logger = self.shell.logger
> logger = undefined
> self.shell.logger = undefined
> 987
> 988 # if no args are given, the defaults set in the logger constructor by
> 989 # ipytohn remain valid
> 990 if par:
> 991 try:
> 992 logfname,logmode = par.split()
> 993 except:
> 994 logfname = par
> 995 logmode = 'backup'
> 996 else:
> 997 logfname = logger.logfname
> 998 logmode = logger.logmode
> 999 # put logfname into rc struct as if it had been called on the command
> 1000 # line, so it ends up saved in the log header Save it in case we need
> 1001 # to restore it...
>
> AttributeError: 'InteractiveShell' object has no attribute 'logger'
>
> ***************************************************************************
>
> History of session input:
>
> *** Last line of input (may not be in above history):
>
> _______________________________________________
> IPython-user mailing list
> IPython-user at scipy.net
> http://scipy.net/mailman/listinfo/ipython-user
>
>
>
--
Ville Vainio - http://tinyurl.com/2prnb
http://vainio.blogspot.com
More information about the IPython-user
mailing list