#!/user/bin/python#-*-coding:utf-8-*-" "subprocess: Need to test shelllogging on Linux platform" "ImportLogging#output The log in a file#logging.basicconfig (filename= "App.log", level=logging. DEBUG)Logging.basicconfig (filename="App.log", level=logging. WARNING, Format='% (asctime) s% (levelname) s% (filename) s:% (lineno) d-% (message) s', Datefmt='%m/%d/%y%i:%m:%s%p')#add time to the log.%p represents PM. TODO Why not hit the number of trips?Logging.debug ("Test Debug") Logging.info ("Test Info") Logging.error ("Test Error") logging.warning ("User [Alex] attempted wrong password more than 3 times")#also print the logs on the screen and output them in the file.#Step 1, create loggerLogger = Logging.getlogger ("Test-log") Logger.setlevel (logging. DEBUG)#Step2, create console handler and set level to debugCh=logging. Streamhandler () Ch.setlevel (logging. DEBUG)#step3, create file handler and set level to warningFH = logging. Filehandler ("Process.log") Fh.setlevel (logging. ERROR)#step3, define formatFh_formatter = logging. Formatter ('% (asctime) s% (levelname) s% (filename) s:% (lineno) d-% (message) s') Ch_formatter= Logging. Formatter ('% (asctime) s-% (name) s-% (levelname) s-% (message) s') Fh.setformatter (fh_formatter) ch.setformatter (ch_formatter)#Step4, connect handlers to loggerLogger.addhandler (FH) logger.addhandler (CH) logger.warning ("ddddd")
Python logger/logging