LogIt(level=10, showargs=False, showret=False, col_limit=0)¶
A function designed to be a decorator of any method of a Logger subclass. The idea is to log the entrance and exit of any decorated method of a Logger subclass. Example:
from taurus.core.util.log import Logger, LogIt class Example(Logger): @LogIt(Logger.Debug) def go(self): print "Hello world "
This will generate two log messages of Debug level, one before the function go is called and another when go finishes. Example output:
MainThread DEBUG 2010-11-15 15:36:11,440 Example: -> go Hello world of mine MainThread DEBUG 2010-11-15 15:36:11,441 Example: <- go
This decorator can receive two optional arguments showargs and showret which are set to False by default. Enabling them will had verbose infomation about the parameters and return value. The following example:
from taurus.core.uti.log import Logger, LogIt class Example(Logger): @LogIt(Logger.Debug, showargs=True, showret=True) def go(self, msg): msg = "Hello world",msg print msg return msg
would generate an output like:
MainThread DEBUG 2010-11-15 15:42:02,353 Example: -> go('of mine',) Hello world of mine MainThread DEBUG 2010-11-15 15:42:02,353 Example: <- go = Hello world of mine
it may happen that in these examples that the output of the method appears before or after the log messages. This is because log messages are, by default, written to the stardard error while the print message inside the go method outputs to the standard ouput. On many systems these two targets are not synchronized.