| Home | Trees | Indices | Help |
|
|---|
|
|
1 #Copyright (c) 2007 2 # Ruben Reifenberg, Germany, 07381. 3 # All rights reserved. 4 # 5 #Redistribution and use in source and binary forms, with or without 6 #modification, are permitted provided that the following conditions 7 #are met: 8 #1. Redistributions of source code must retain the above copyright 9 # notice, this list of conditions and the following disclaimer as 10 # the first lines of this file unmodified. 11 #2. Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 # SUCH DAMAGE. 26 27 """ 28 @summary: 29 Indent message texts depending on callers stack depth. 30 @author: Ruben Reifenberg 31 """ 32 33 from rrlog.tool import StrIndenter 3436 """ 37 At the first log call, it adjusts itself to zero indention. 38 You can later adjust (tara) with each log call. Use 39 log( ..., stackindent_tara=0). 40 This will adjust the current call to be zero-indented. 41 Use -1 to immediately indent by 1 etc. 42 (Negative indention is ignored, these lines appear not-indented.) 43 """75 7645 """ 46 @param token: The string used to indent one level. 47 @param msgPrefix: str. If given, indent only messages starting with 48 this prefix. All other messages are ignored (they cannot even trigger a "tara"). 49 """ 50 self._si = StrIndenter(token=token) 51 self._dotara = True 52 self.msgPrefix = msgPrefix5355 job = jobhist[-1] 56 57 if self.msgPrefix is not None: 58 # ignore jobs without the right msg prefix 59 if not job.msg.startswith(self.msgPrefix): return 60 61 # do tara in two cases: 62 # when we get the first call, or 63 # when we get a tara request with the job 64 try: 65 tara = job.special["stackindent_tara"] 66 self._dotara = True 67 except KeyError: 68 if self._dotara: 69 tara = 0 70 if self._dotara: 71 self._si.tara(job.tblen, tara) 72 self._dotara = False 73 # print "job.tblen=%s (%s,%s)"%(job.tblen,job.msg,str(job.path)) 74 job.msg=self._si(job.tblen)+job.msg78 """ 79 convenience function for the standard scenario 80 "log locally to standard out and indent." 81 @param token: str, the indention token 82 @return: local log 83 """ 84 from rrlog.server.printwriter import createLocalLog 85 return createLocalLog( 86 filters=(StackIndentFilter(token=token),), 87 **kwargs 88 )89
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu May 20 11:46:18 2010 | http://epydoc.sourceforge.net |