Python教程

Python--logger日志

本文主要是介绍Python--logger日志,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# -*- coding:utf-8 -*-

import logging

from logging import handlers


def logger(log_file):
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    handler = handlers.TimedRotatingFileHandler(log_file,
                                       when="D",
                                       interval=1,
                                       backupCount=7)
    formatter = logging.Formatter(
        "%(asctime)s - %(funcName)s- %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    return logger

 

这篇关于Python--logger日志的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!