这是种子文件跟踪项目。
seed-papertrail的Python项目详细描述
一些实用程序来计时和记录事情。
>>>importlogging>>>formatter=logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")>>>logger=logging.getLogger('papertrail')>>>consoleHandler=logging.StreamHandler()>>>consoleHandler.setFormatter(formatter)>>>logger.addHandler(consoleHandler)>>>logger.setLevel(logging.DEBUG)
用作函数装饰符
>>>fromseed_papertrail.decoratorsimportpapertrail>>>@papertrail.warn...deftesting():print1...>>>testing()12017-01-2411:16:02,100[MainThread][WARNI]__main__.testing0.000021:
还可以指定自定义日志消息和示例大小参数:
>>>@papertrail.warn('this is likely to explode',sample=0.5)...deftesting():print1...>>>testing()1>>>testing()1>>>testing()12017-01-2411:38:56,068[MainThread][WARNI]__main__.testing0.000018:thisislikelytoexplode>>>testing()12017-01-2411:38:59,628[MainThread][WARNI]__main__.testing0.000019:thisislikelytoexplode>>>testing()1>>>
用作上下文管理器
>>>fromseed_papertrail.decoratorsimportpapertrail>>>withpapertrail.timer('hulloo')asl:...l.debug('more logging here!')...print1...2017-01-2411:32:23,109[MainThread][DEBUG]morelogginghere!12017-01-2411:32:23,115[MainThread][DEBUG]0.002581:hulloo,threshold:OK>>>
您还可以指定自定义阈值:
>>>withpapertrail.timer('o_O',thresholds={'OK':(0,0.1),'FAIL':(0.1,1000)}):...time.sleep(6)...2017-01-2411:45:00,717[MainThread][DEBUG]6.000664:o_O,threshold:FAIL
另外,timer函数允许指定以下关键字参数:
- level日志记录级别,默认为DEBUG
- logger要登录的记录器,默认为papertrail