是否有一种方法来抑制海王星库输出的调试消息?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)以下是我收到的调试消息:
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}})发布于 2022-07-01 14:21:15
备选案文1
这似乎有悖常理,但将mode=debug模式传递给海王星将压制与海王星相关的调试消息:
tracker = neptune.init(
project=f'WORKSPACE/PROJECT_NAME',
mode="debug",
capture_hardware_metrics=False,
source_files=[],
capture_stdout=False,
capture_stderr=False
)启用此功能的另一种方法是设置环境变量CONNECTION_MODE。
选项2
如果您希望能够微调记录到海王星网站/服务器的消息,请考虑使用海王星客户端提供的NeptuneHandler。
示例:
>>> import logging
>>> import neptune.new as neptune
>>> from neptune.new.integrations.python_logger import NeptuneHandler
>>> logger = logging.getLogger("root_experiment")
>>> logger.setLevel(logging.INFO)
>>> run = neptune.init(project="neptune/sandbox")
>>> npt_handler = NeptuneHandler(run=run) # you can also pass `level=logging.INFO` here
>>> logger.addHandler(npt_handler)
>>> logger.info("Starting data preparation")
...
>>> logger.info("Data preparation done")上面的示例将所有日志级别(严重程度>调试)发送到Neptune网站/服务器。作为参考,python的日志级别严重性如下(临界>错误>警告>信息>调试)。我在下面的参考资料中包含了Python关于这个主题的文档。
参考文献
https://docs.neptune.ai/you-should-know/connection-modes#debug
https://docs.neptune.ai/api-reference/integrations/python-logger
https://docs.python.org/3/howto/logging.html#when-to-use-logging
发布于 2022-05-03 15:50:51
你可以完全禁用stdout。使用下列功能:
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()警告:
这是一种相当危险的方法,因为它可能隐藏其他重要/有用的信息。
把它当作最后的手段
发布于 2022-06-28 14:47:56
您可以使用logging模块。
简单地,通过使用logging.getLogger导入模块并获取记录器实例,然后使用setLevel函数,将level参数作为您想要显示的警告类型(即之前要忽略的问题类型)上的级别传递。
由于这些都是调试消息,您可以使用logging.CRITICAL设置一个类似关键的级别,这将导致忽略来自该库的调试消息。
阅读https://docs.python.org/3/library/logging.html#logging.Logger.setLevel以获得更多信息
https://stackoverflow.com/questions/72101713
复制相似问题