0

I would like to parse my JSON log with jq, but my command didn't work anymore since few months.

I use tail from azure-cli command to show live log from my webapp

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

I use roarr to parse log, but it's a detail

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

Exemple of logs received by 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"}

My expression clean the time header added by azure, but it's not working anymore

It look like there are no "\n" on log streamed by azure... or it like it's in one block, so impossible to parse JSON ...

Do you have any idea? How do you achieve that?

Vincent Vost
  • 11
  • 1
  • 4

1 Answers1

0

The /g modifier must not being used here, just:

< azure.log sed 's/[^{]*//;s/[^}]*$//' | jq
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • Thank you, you sed is better. I've try with a file, it work perfectly. but I still get the problem with azure tail, it's like there are no "\n", but i see them – Vincent Vost Sep 09 '21 at 09:06
  • maybe it's using [Windows linefeeds](https://en.wikipedia.org/wiki/Newline#Representation)? that would be `\r\n` instead of just `\n` – hek2mgl Sep 09 '21 at 14:11