###
#-*-Coding:utf-8-*-
Import logging
Import Logging.handlers
#Log DirectoryLog_file ='Log.zk'log_fmt='% (asctime) s-% (filename) s-% (levelname) s-% (message) s'date_fmt='%a,%d%b%Y%h:%m:%s'#The format of the instantiated FORMATTER,DATEFMT is formatted using Yime.strftime (format[, T])Formatter=logging. Formatter (fmt=log_fmt,datefmt=date_fmt)#Thu, Sep 10:46:29-log.py-error-the ERROR MESSAGE#Create a handler processorHandler =Logging.handlers.RotatingFileHandler (log_file)#add a log format to handlerHandler.setformatter (Formatter)#Create a Logger instanceLogger = Logging.getlogger ('Log.zk')#Setting the log levelLogger.setlevel (logging. ERROR)#Add a processorLogger.addhandler (handler) Logger.debug ('The DEBUG MESSAGE') Logger.info ('The INFO MESSAGE') logger.warning ('The WARN MESSAGE') Logger.error ('The ERROR MESSAGE') logger.critical ('The critical MESSAGE')
###
#-*-Coding:utf-8-*-
Import logging
Import Logging.handlers
#FileName: Log name, Level log class (logs with output info above include info)Logging.basicconfig (filename='Log.kafka', level=logging.info,format='% (asctime) s-% (filename) s-% (levelname) s-% (message) s') Logging.debug ('The DEBUG MESSAGE') Logging.info ('The INFO MESSAGE') logging.warning ('The WARN MESSAGE') Logging.error ('The ERROR MESSAGE') logging.critical ('The critical MESSAGE')
###
Reference blog:
http://blog.csdn.net/zyz511919766/article/details/25136485
Python #logging