【问题标题】:Suppressing debug messages from neptune library抑制来自海王星库的调试消息
【发布时间】:2022-06-28 22:22:10
【问题描述】:

有没有办法抑制 NEPTUNE 库输出的 DEBUG 消息? https://github.com/neptune-ai/neptune-client

这就是我目前正在做的事情:

tracker = neptune.init(project=f'WORKSPACE/PROJECT_NAME',
                       capture_hardware_metrics=False,
                       source_files=[],
                       capture_stdout=False,
                       capture_stderr=False)

这些是我收到的 DEBUG 消息:

2022-05-03  11:31:58 DEBUG https://app.neptune.ai:443 "POST /api/leaderboard/v1/attributes/ping?experimentId=aaa HTTP/1.1" 200 0
2022-05-03  11:32:08 DEBUG ping({'experimentId': 'aaa', '_request_options': {'timeout': 10, 'connect_timeout': 10}})

【问题讨论】:

  • 您可以通过将空列表传递给 neptune.init(): run = neptune.init(..., source_files=[]) 的 source_files 参数来关闭源代码的日志记录
  • @Thornily,我已经这样做了,但仍然收到大量 DEBUG 消息
  • 我很确定没有其他办法了

标签: python


【解决方案1】:

您可以完全禁用标准输出。 使用以下函数:

import sys, os

# Disable
def disable_stdout():
    sys.stdout = open(os.devnull, 'w')

# Restore
def enable_stdout():
    sys.stdout = sys.__stdout__

例子:

disable_stdout()

<Code to Run without logging/printing>

enable_stdout()

警告:
这是一种非常危险的方法,因为它可能会隐藏其他重要/有用的消息。
使用它作为最后的手段

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多