Azure webapp 日志尾部解析失败

Posted

技术标签:

【中文标题】Azure webapp 日志尾部解析失败【英文标题】:Azure webapp log tail fail parsing 【发布时间】:2021-11-05 13:23:50 【问题描述】:

我想用 jq 解析我的 JSON 日志,但是几个月后我的命令就不再起作用了。

我使用 azure-cli 命令的 tail 从我的 webapp 显示实时日志

az webapp log tail --resource-group $RESOURCE --name $appNAME | sed 's/^[^]*//g' | sed 's/[^]*$//g' | jq -r .

我用 roarr 来解析日志,但这是一个细节

az webapp log tail --resource-group $RESOURCE --name $appNAME | sed 's/^[^]*//g' | sed 's/[^]*$//g' | roarr --exclude-alien true --use-colors --output-format pretty

azure 收到的日志示例:

2021-09-08T19:04:34.555601536Z "context":"package":"slonik","poolId":"xynV9RGHSBewXN4hftNfaQ-0","logLevel":20,"processId":-140462480,"stats":"idleConnectionCount":0,"totalConnectionCount":1,"waitingRequestCount":0,"message":"client is checked out from the pool","sequence":648,"time":1631127874554,"version":"1.0.0"
2021-09-08T19:04:34.561488913Z "context":"package":"slonik","poolId":"xynV9RGHSBewXN4hftNfaQ-0","logLevel":20,"processId":-140462480,"stats":"idleConnectionCount":0,"totalConnectionCount":1,"waitingRequestCount":0,"message":"client is checked out from the pool","sequence":649,"time":1631127874560,"version":"1.0.0"
2021-09-08T19:04:34.567543092Z "context":"package":"slonik","poolId":"xynV9RGHSBewXN4hftNfaQ-0","logLevel":20,"processId":-140462480,"stats":"idleConnectionCount":0,"totalConnectionCount":1,"waitingRequestCount":0,"message":"client is checked out from the pool","sequence":650,"time":1631127874567,"version":"1.0.0"
2021-09-08T19:04:34.815734729Z "context":"package":"slonik","poolId":"xynV9RGHSBewXN4hftNfaQ-0","logLevel":20,"processId":-140462480,"stats":"idleConnectionCount":0,"totalConnectionCount":1,"waitingRequestCount":0,"message":"client is checked out from the pool","sequence":651,"time":1631127874814,"version":"1.0.0"

我的表情清理了 azure 添加的时间标头,但它不再起作用了

看起来 azure 流式传输的日志中没有“\n”...或者它就像在一个块中,因此无法解析 JSON ...

你有什么想法吗?你是怎么做到的?

【问题讨论】:

【参考方案1】:

/g 修饰符不能在这里使用,只是:

< azure.log sed 's/[^]*//;s/[^]*$//' | jq

【讨论】:

谢谢,sed 更好。我试过一个文件,它工作得很好。但我仍然遇到 azure tail 的问题,就像没有“\n”,但我看到了它们 也许它正在使用Windows linefeeds?那将是\r\n 而不仅仅是\n

以上是关于Azure webapp 日志尾部解析失败的主要内容,如果未能解决你的问题,请参考以下文章

Azure 逻辑应用 - 解析 JSON 架构失败“对象中缺少必需的属性”

Azure databricks:通过 API 将 maven 库安装到集群会导致错误(库解析失败。原因:java.lang.RuntimeException)

从存储容器恢复 Azure Linux webapp 备份失败 PowerShell

在 Azure WebApp 部署中设置应用服务日志的保留期

构建 VSTS 扩展 azure webapp 身份验证 JWT 令牌验证失败

由于ZIP的结构,使用kudu ZipDeploy的Azure webapp部署失败