簡體   English   中英

如何在 Python Quart 路由處理程序中使用日志記錄?

[英]How to use logging in Python Quart route handler?

我是新來hypercorn + uvloop + quart 我正在嘗試創建以下文件並在路由處理程序中打印一些信息/調試日志,但沒有顯示任何內容。 我已經調試到路由處理程序並注意到dog_server.logger.disabled = True 有誰知道是什么問題? 謝謝!

dog_blueprint.py

from quart import Blueprint
import logging

logging.basicConfig(level=logging.DEBUG)

class DogBlueprint(Blueprint):
    logger = None
    app_config = None

    def register(self, app, options, first_registration: bool = False):
        # app.logger.info('DogBlueprint is registering')
        print('Blueprint registering...')
        self.logger = app.logger 
        self.logger.info("Hello")  # This one working fine
        self.app_config = app.config
        super(DogBlueprint, self).register(app, options, first_registration)
        self.logger.info("World")  # This one working fine

路線.py

dog_server = DogBlueprint('dog_server', __name__)
logging.basicConfig(level=logging.DEBUG)

@dog_server.route('/score', methods=['POST'])
async def post_handler():
    received = await _fetch_post_body(request)
    dog_server.logger.info(f'Received size: {len(received)}')  # This one does not work
    ... ... 

這是 Hypercorn 中的一個錯誤,請參閱此討論 我會避免使用 0.11.0 並使用 0.10.2 或 0.11.1。 (我是 Hypercorn 的作者)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM