My color log configuration

I spent some time making a pretty colored log format that maybe you might like to use as well.

This uses the transform encoder plugin:

Place this in your Caddyfile’s global options:

{
	log http.log.access {
		include http.log.access
		output file /var/log/caddy/access.log
		format transform "e[35m[{ts}]e[0m e[96me[1m{request>remote_ip}e[0m e[31m{request>headers>X-Forwarded-For}e[0m e[33m{request>method}e[0m e[92m{request>host}e[32m{request>uri}e[0m e[97m{status}e[0m	e[90m{request>headers>User-Agent}e[0m e[34m{request>headers>Referer}e[0m" {
			time_format "02/Jan/2006:15:04:05-0700"
		}
	}
	log {
		exclude http.log.access
		output file /var/log/caddy/caddy.log
		format json
	}
}

Edit: the forum is replacing the ANSI escape codes with the letter e >:(
So here’s a gist 53244678f5290978d19a75ce0f7e0bf6/gistfile1.txt at master - 53244678f5290978d19a75ce0f7e0bf6 - gitea.moe

It looks like this :slightly_smiling_face:

6 Likes

@ledlamp looks like your github gist was removed, and the link is now dead. Do you still have it?

yeah… 53244678f5290978d19a75ce0f7e0bf6/gistfile1.txt at master - 53244678f5290978d19a75ce0f7e0bf6 - gitea.moe

It seems like that gitea gist also has the broken 0x001B characters as well in the raw output :thinking:

on chrome on windows I was able to copy from raw just fine, but pasting in nano broke the ansi codes. I had to scp the caddyfile to my computer and paste in notepad++.

also updated gist for caddy 2.5

1 Like

Hi @ledlamp, what command did you run to see these?