How to obtain nginx style of access log


I’m switching to Caddy from nginx, and I’m trying to replicate its behaviour in many parts in order to keep my habits. One area where I’m not happy is access logs. Either single_field common_log, which is too little, or full json, which is difficult to read.
How could I get an access log output like the one with default nginx?

'$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"'

Even if some of those fields are not possible to get (body bytes sent), everything else is present in the json. Help is really appreciated

You can use this plugin to make a custom log encoding based on the fields provided in the JSON:

/cc @Mohammed90 in case you have any tips to add

1 Like

For reference, this is a sample of the JSON log message:

	"request": {
		"remote_addr": "[::1]:60457",
		"proto": "HTTP/2.0",
		"method": "GET",
		"host": "localhost",
		"uri": "/",
		"headers": {
			"User-Agent": [
				"Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"
			"Accept": [
			"Accept-Language": [
			"Upgrade-Insecure-Requests": [
			"Accept-Encoding": [
				"gzip, deflate, br"
			"Te": [
		"tls": {
			"resumed": false,
			"version": 772,
			"cipher_suite": 4865,
			"proto": "h2",
			"proto_mutual": true,
			"server_name": "localhost"
	"common_log": "::1 - mohammed [24/Nov/2020:02:26:15 +0300] \"GET / HTTP/2.0\" 200 83676",
	"duration": 1.065969691,
	"size": 83676,
	"status": 200,
	"resp_headers": {
		"Server": [
		"Content-Type": [
			"text/html; charset=utf-8"

Note that replacing placeholders of not present values with - (or whatever string you want) is implemented in master’s latest commit, but not part of a released tag yet.

This topic was automatically closed after 30 days. New replies are no longer allowed.