【问题标题】:Azure webapp log tail fail parsingAzure webapp 日志尾部解析失败
【发布时间】: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 ...

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

【问题讨论】:

    标签: sed azure-cli tail azure-webapps


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,sed 更好。我试过一个文件,它工作得很好。但我仍然遇到 azure tail 的问题,就像没有“\n”,但我看到了它们
    • 也许它正在使用Windows linefeeds?那将是\r\n 而不仅仅是\n
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    相关资源
    最近更新 更多