为什么在Azure Dev Ops管道中将Python记录视为错误

发布于 2025-02-11 14:21:41 字数 720 浏览 1 评论 0 原文

我有问题。在我的项目中,我正在使用Python Logging,以描述程序的每个步骤。代码很简单:

log = logging.getLogger()
logging.basicConfig(
    handlers=[
        logging.FileHandler("./logs/{:%d-%m-%Y}/".format(datetime.now())+"{:%Y-%m-%d-%H-%M-%S}.log".format(datetime.now()), 'w', 'utf-8'),
        logging.StreamHandler()
    ],
    level=logging.INFO,
    format='[%(asctime)s] %(levelname)s - %(message)s',
    datefmt='%H:%M:%S'
)

我不知道为什么,但是Azure Dev Ops中的管道自动将每个日志视为错误,无论日志是信息类型或错误的类型:

”一切都是红色的。 我该如何修复?

I have a problem. In my project I'm using python logging, to describe every single step of my program. Code is simple:

log = logging.getLogger()
logging.basicConfig(
    handlers=[
        logging.FileHandler("./logs/{:%d-%m-%Y}/".format(datetime.now())+"{:%Y-%m-%d-%H-%M-%S}.log".format(datetime.now()), 'w', 'utf-8'),
        logging.StreamHandler()
    ],
    level=logging.INFO,
    format='[%(asctime)s] %(levelname)s - %(message)s',
    datefmt='%H:%M:%S'
)

I don't know why, but pipeline in Azure Dev Ops automaticly treats every log as error, no matter that log is type of INFO or ERROR:

enter image description here

Same thing is in console output, everything is in red.
How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

述情 2025-02-18 14:21:41

这是Azure DevOps中的默认情况,实际上是将Python记录为警告错误。要使日志记录在Azure DevOps中使用完美,请按照以下步骤操作。

设置loggin级别:

import logging

logger = logging.getLogger('azure.mgmt.resource')

# Set the desired logging level
logger.setLevel(logging.DEBUG)

使用常规名称空间:

import logging

logger = logging.getLogger('azure.storage')
logger.setLevel(logging.INFO)

logger = logging.getLogger('azure')
logger.setLevel(logging.ERROR)

print(f"Logger enabled for ERROR={logger.isEnabledFor(logging.ERROR)}, " \
    f"WARNING={logger.isEnabledFor(logging.WARNING)}, " \
    f"INFO={logger.isEnabledFor(logging.INFO)}, " \
    f"DEBUG={logger.isEnabledFor(logging.DEBUG)}")

这是标准记录库

查看有关官方程序的文档,以处理

That is a default case in Azure DevOps actually to consider python logging as Warning or Error. To make the logging to use perfect in azure DevOps follow the steps below.

enter image description here

Set Loggin Level:

import logging

logger = logging.getLogger('azure.mgmt.resource')

# Set the desired logging level
logger.setLevel(logging.DEBUG)

Use General Namespaces:

import logging

logger = logging.getLogger('azure.storage')
logger.setLevel(logging.INFO)

logger = logging.getLogger('azure')
logger.setLevel(logging.ERROR)

print(f"Logger enabled for ERROR={logger.isEnabledFor(logging.ERROR)}, " \
    f"WARNING={logger.isEnabledFor(logging.WARNING)}, " \
    f"INFO={logger.isEnabledFor(logging.INFO)}, " \
    f"DEBUG={logger.isEnabledFor(logging.DEBUG)}")

This is the link of standard logging libraries.

Check out the documentation on official procedure to handle the logging

情感失落者 2025-02-18 14:21:41

当您在没有参数的情况下创建 streamHandler 时,它将输出到 stderr 。这是标准错误流,会导致Azure表示其输出为错误。

https:///docs.python.org/3/library/ logging.handlers.html#logging.streamhandler

When you create a StreamHandler without arguments, it will output to stderr. That being a Standard Error stream, causes Azure to show its output as errors.

https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文