【发布时间】: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