zoukankan      html  css  js  c++  java
  • flask 日志级别设置只记录error级别及以上的问题

    当我在设置flask 日志时

    handler = logging.FileHandler('flask.log', encoding='UTF-8')
        handler.setLevel(logging.DEBUG)
        logging_format = logging.Formatter(
            '%(asctime)s - %(levelname)s -%(pathname)s- %(filename)s - %(funcName)s - %(lineno)s - %(message)s'
        )
    handler.setFormatter(logging_format)
    app.logger.addHandler(handler)

    flask 使用时

    from flask import current_app
    
    @app.route('/hello')
    def hell():
        current_app.logger.info('----------------info----------------')
        current_app.logger.error('----------------err----------------')
        current_app.logger.debug('----------------debug----------------')
        current_app.logger.warning('----------------warning----------------')
        return 'hello World'

    在flask.log 中记录的日志只有error级别以上

    2019-12-13 17:41:28,189 - ERROR -/home/frange/servers/Allocation/manage.py- manage.py - hell - 24 - ----------------err----------------
    2019-12-13 17:41:28,189 - WARNING -/home/frange/servers/Allocation/manage.py- manage.py - hell - 26 - ----------------warning----------------

    处理

    在创建app之前将log 级别重置为debug

    logging.basicConfig(level=logging.DEBUG)
  • 相关阅读:
    UVa 10055
    UVa 401
    c++中文件应用的一点小变化
    poj2136
    UVa 494
    一台电脑接两个显示器,双屏显示介绍zz
    学习jquery合集
    解决Windows下MinGW显示乱码zz
    QWS_MOUSE_PROTO该如何写
    Qt/e中鼠标设备分析
  • 原文地址:https://www.cnblogs.com/Frange/p/12036572.html
Copyright © 2011-2022 走看看