This article mainly introduces the python log writing encapsulation class. The example analyzes the skills related to Python operation logs. If you need it, you can refer to the example in this article to describe the python log writing encapsulation class. Share it with you for your reference. The details are as follows:
# Encoding: utf-8import sysimport loggingimport timedef writeLog (message): logger = logging. getLogger () filename = time. strftime ('% Y-% m-% d', time. localtime (time. time () handler = logging. fileHandler (". /log/"+ filename +" error ") logger. addHandler (handler) logger. setLevel (logging. NOTSET) logger.info (message) if _ name _ = '_ main _': writeLog ("hello ")
Save this code as TLog. import TLog before calling, and then TLog. writelog ("jb51.net ").
I hope this article will help you with Python programming.