[英]How To: Flask Use Global Logger
How can I tell a Flask application to use a specific instance of a logger that already exists? 如何告诉Flask应用程序使用已存在的记录器的特定实例? I have a logger that is already created (and logging) and I'd like to say to my Flask app "hey, use this logger". 我有一个已经创建(和记录)的记录器,我想对我的Flask应用程序说“嘿,使用这个记录器”。
All I can see that is possible is to call: 所有我能看到的可能是打电话:
my_flask_app.logger.addHandler(handler) my_flask_app.logger.addHandler(句柄)
But I don't want to pass it a handler. 但我不想把它传递给处理程序。 Won't that just create a separate logger? 那不就是创建一个单独的记录器吗? I see within the Flask code it call create_logger. 我在Flask代码中看到它调用create_logger。
Thoughts? 思考? Thanks in advance... 提前致谢...
In case some else stumbled across this: 万一其他人偶然发现了这个:
app.config["LOGGER_NAME"] = your_logger_name
app._logger = logger
will prevent flask from creating logger, and will use yours instead. 将阻止烧瓶创建记录器,并将使用你的。
Quite ugly going to _logger
but didn't find other solution for it. 很难_logger
但没有找到其他解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.