为什么在Azure Dev Ops管道中将Python记录视为错误
我有问题。在我的项目中,我正在使用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中的管道自动将每个日志视为错误,无论日志是信息类型或错误的类型:
”一切都是红色的。 我该如何修复?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是Azure DevOps中的默认情况,实际上是将Python记录为警告或错误。要使日志记录在Azure DevOps中使用完美,请按照以下步骤操作。
设置loggin级别:
使用常规名称空间:
这是标准记录库。
查看有关官方程序的文档,以处理
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.
Set Loggin Level:
Use General Namespaces:
This is the link of standard logging libraries.
Check out the documentation on official procedure to handle the logging
当您在没有参数的情况下创建
streamHandler
时,它将输出到stderr
。这是标准错误流,会导致Azure表示其输出为错误。https:///docs.python.org/3/library/ logging.handlers.html#logging.streamhandler
When you create a
StreamHandler
without arguments, it will output tostderr
. 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