#!/usr/bin/env python#CODING=GBKImportLogging, OSclassLogger:def __init__(Self, path, clevel=logging. DEBUG, flevel=logging. DEBUG): Self.logger=Logging.getlogger (path) self.logger.setLevel (logging. DEBUG) FMT= Logging. Formatter ('[% (asctime) s] [% (levelname) s]% (message) s','%y-%m-%d%h:%m:%s') #set cmd logSH =logging. Streamhandler () sh.setformatter (FMT) sh.setlevel (clevel)#Set File LogFH =logging. Filehandler (Path) fh.setformatter (FMT) fh.setlevel (flevel) self.logger.addHandler (SH) self.log Ger.addhandler (FH)defDebug (self, message): Self.logger.debug (message)definfo (self, message): Self.logger.info (message)defWar (self, Message): Self.logger.warn (message)deferror (self, message): Self.logger.error (message)defCRI (self, Message): self.logger.critical (message)if __name__=='__main__': Logyyx= Logger ('Yyx.log', logging. DEBUG, logging. DEBUG) Logyyx.debug ('a debug message') Logyyx.info ('an info info') Logyyx.war ('A warning information') Logyyx.error ('an error message') Logyyx.cri ('A deadly critical message')
Python Logger Log Tool class