# 初始化日志

def initLog():
    """
    初始化日志
    :return:
    """
    import logging
    handler = logging.FileHandler('logs/flask.log', encoding='UTF-8')
    handler.setLevel(logging.DEBUG)
    logging_format = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
    file_log_handler = RotatingFileHandler('WarningLogs.log', maxBytes=1024 * 1024, backupCount=10)
    handler.setFormatter(logging_format)
    logging.getLogger().addHandler(handler)
    logging.getLogger().addHandler(file_log_handler)
    app.logger.addHandler(handler)
    app.logger.addHandler(file_log_handler)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 使用日志

logging.getLogger(app.name).info("abd")
1