python logging类库使用例子
一、简单使用
defTestLogBasic(): importlogging logging.basicConfig(filename='log.txt',filemode='a',level=logging.NOTSET,format='%(asctime)s-%(levelname)s:%(message)s') logging.debug('thisisamessage') logging.info("thisisainfo") logging.disable(30)#logging.WARNING logging.warning("thisisawarnning") logging.critical("thisisacriticalissue") logging.error("thisisaerror") logging.addLevelName(88,"MyCustomError") logging.log(88,"thisisanmycustomerror") try: raiseException('thisisaexception') except: logging.exception('exception') logging.shutdown()
TestLogBasic()