I open this thread to discuss strategies to use the JSON logs created by Caddy 2.
Since I’m mostly using the command
tail to consume the logs directly in my terminal window, the default presentation is not great at all :
I found a really simple solution though. I installed jq and now I can output a more readable log just by adding
jq after the
tail, like this :
tail -f /var/log/caddy/voiretmanger.fr.access.log | jq
This is what I get (I’m using ZSH and oh-my-zsh, which explains the colors used) :
Another benefit of jq is that you can filter the output to display only one information. For instance, if you only want to see the requests uri, you can do :
tail -f /var/log/caddy/voiretmanger.fr.access.log | jq .request.uri
And this is what you will get :
You could use that filter to display the common log, still available in the default log outputted by Caddy 2 :
tail -f /var/log/caddy/voiretmanger.fr.access.log | jq .common_log
You can even display multiple informations at once, using a comma between each element, like so :
tail -f /var/log/caddy/voiretmanger.fr.access.log | jq '.request.uri, .request.remote_addr'
The jq documentation contains more example of filtering available : https://stedolan.github.io/jq/manual/#Basicfilters
It’s pretty basic, but it’s usually enough for my limited needs. If you have a different system, I would be interested to see what you do !