python写日志

import logging
from logging.handlers import RotatingFileHandler

_ONE_DAY_IN_SECONDS = 60 * 60 * 24
app = Flask(__name__)

logger = logging.getLogger("log_file")
logger.setLevel(logging.DEBUG)

logdirs = "D:/PythonLog/"
if not os.path.exists(logdirs):
	os.makedirs(logdirs)
logdirs += "win32GRPCClient.log"
fh =  RotatingFileHandler(logdirs,maxBytes=1024*1024,backupCount=40,mode='a')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt="%(asctime)s-%(levelname)s : %(message)s", datefmt='%Y-%m-%d %H:%M:%S')
fh.setFormatter(formatter)
logger.addHandler(fh)

if __name__ == '__main__':
    logger.debug("test test()")

 

你可能感兴趣的:(Python)