以绘图破折号显示后端日志消息

2024-09-26 22:50:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用Plotly Dash为基于JVM的(Kotlin)服务开发仪表板。实际上,JVM服务将消息(通过ZMQ)推送到我的Python Dash脚本,该脚本反过来更新一系列实时图表。在

除了图表之外,我还希望在仪表板中显示服务的日志消息(它们当前显示在控制台中并写入文件)。我可以很容易地修改JVM-app/Python脚本来通过ZMQ发送/接收消息,但是我还没有找到一个可以实时显示这些消息的Dash组件。在

由于消息的吞吐量相当高(每秒几十条),我希望能够按级别(信息、警告等)和其他标准(regex是理想的)过滤消息。我阅读了Dash文档,但找不到适合我需要的组件。有没有办法在冲刺中做到这一点?在

谢谢你的帮助!在


Tags: 文件脚本信息app消息图表组件仪表板
1条回答
网友
1楼 · 发布于 2024-09-26 22:50:53

我不熟悉如何接收脚本中的消息,但您要使用的内容包括:

  • 一个普通的html.Div(id='log-div',style=dict(height='300px',overflow='auto')),它只是一个可滚动的空div
  • 一个dcc.Interval,每n秒触发一次新日志
  • 一个回调函数,看起来像
@app.callback(
  Output('log-div','children'),
  [Input('log-interval','n_intervals')],
  [State('log-div','children')]
)
def log_content(n_intervals,old_logs):
    # take in the messages through some function
    messages = receive_messages_function()

    # filter the messages here
    messages = filter_messages_function()

    # old_logs is a list of the old messages, with each line being a 
    # separate div (to separate the messages, this can be done in many different ways).
    # So what you do is add the new filtered messages to the old filtered messages
    # Note - this assumes the messages are in a list of some sort; it doesn't matter
    # as the concept is the same - just add the new messages after the old ones
    messages = old_logs + messages

    return messages   

注意-旧的回答不正确。在

希望这有帮助!如果有任何问题/反馈,我很乐意回答。在

相关问题 更多 >

    热门问题