ImportLogginglogging.basicconfig ( level=logging. DEBUG, Format='% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s', Datefmt='%a,%d%b%Y%h:%m:%s', filename='/tmp/test.log', FileMode='W') Logging.debug ('Debug Message') Logging.info ('Info Message') logging.warning ('warning Message') Logging.error ('error Message') logging.critical ('Critical Message')
ImportLogging#Set Root LoggerR =logging.getlogger () ch=logging. Streamhandler () Ch.setlevel (logging. DEBUG) Formatter= Logging. Formatter ('% (asctime) s-% (levelname) s-% (message) s') Ch.setformatter (formatter) r.addhandler (CH)#Create a logger as a fatherp = Logging.getlogger ('Foo') P.setlevel (logging. DEBUG) Ch=logging. Streamhandler () Ch.setlevel (logging. DEBUG) Formatter= Logging. Formatter ('% (asctime) s-% (message) s') Ch.setformatter (formatter) p.addhandler (CH)#Create a child loggerc = Logging.getlogger ('Foo.bar') C.debug ('Foo')
Configuration and use of the Python logging log module