【发布时间】:2020-01-16 19:54:24
【问题描述】:
在我的 Flask 应用程序中引入 Plotly 仪表板时,我看到了意外行为。每个 Plotly 仪表板都会导致 Flask 日志条目重复。
例如,如果我将两个 Plotly 仪表板附加到我的 Flask 应用程序,日志条目(例如 current_app.logger.info('hi'))将在我的日志中出现 3 次。如果我删除 Plotly 仪表板,日志条目会出现一次,这是预期的行为。
我尝试通过app.logger.handlers.clear() 删除我的日志记录配置代码中的现有处理程序,并将dictConfig 的disable_existing_loggers 设置为True,这两种方法都不会记录任何内容。我还尝试使用单例方法来配置记录器(再次使用dictConfig),但我仍然看到日志条目重复多次。
如何防止 Plotly 仪表板导致重复的日志条目?
更新:
以下是 Dash 应用程序初始化的简化版本:
def register_dashapp(app):
from dashboards.dash_files.my_dash import (
define_layout,
define_callbacks,
)
my_dashapp = dash.Dash(__name__,
server=app,
url_base_pathname='/my_dash/',
assets_folder="../dashboards/foo/bar/assets",
)
with app.app_context():
my_dashapp.title = "Test"
define_layout(my_dashapp)
define_callbacks(my_dashapp)
def create_app():
app = Flask(__name__, instance_relative_config=False)
app.config.from_object('config.Config')
with app.app_context():
register_extensions(app)
app.register_blueprint(main)
register_dash_app(app)
return app
【问题讨论】:
-
app.run_server的代码是什么样的? -
另外,您的记录器上的配置代码是什么?
-
我正在使用this 方法进行日志配置,但我仍然看到这个问题根本没有配置日志记录。我没有使用
run_server,但我会在我的问题中添加一个基本版本的 Dash 初始化。
标签: python flask plotly-dash