Log formating issue

1. The problem I’m having:

If I use unaltered logging output via output file caddy.log, the output looks okay but I want to apply formatting params:
time_format wall
time_local

This is where the problem starts. I was able to get these params to work except I had to go thru format encoder, like:

log caddy-log {
	output file caddy.log
	format console {
		time_format wall
		time_local
	}
}

but I don’t want to format the console per se, I just want to edit the field values. When I do the above, I get some trash (that I don’t get when not using any formatting), e.g.:
2023/07/22 18:26:07 e[34mINFOe[0m tls.cache.maintenance started background certificate maintenance {"cache": "0xc00021c8c0"}

So, is there a way to apply the field value changes w/o having to format the console?

2. Error messages and/or full log output:

n/a

3. Caddy version:

2.6.4

4. How I installed and ran Caddy:

a. System environment:

Win10 Pro x64

b. Command:

caddy run

d. My complete Caddy config:

(as it is now, until I get the log formatting worked out)

{
	email myemail@email.net
	default_sni justinsdomain.com
	servers :8443 {
		protocols h2 h1
	}
	#log stdout
	log caddy-log {
		output file caddy.log	
	}
}
(headers) {
	header {
		Strict-Transport-Security "max-age=31536000; includeSubDomains;"
    		X-Xss-Protection "1; mode=block"
    		X-Content-Type-Options "nosniff"
    		X-Frame-Options "SAMEORIGIN"
    		Content-Security-Policy "upgrade-insecure-requests"
    		Referrer-Policy "strict-origin-when-cross-origin"
    		Cache-Control "public, max-age=15, must-revalidate"
	}
}
(logging) {
	log {
		output file "{args.0}.log"
	}
}
#file server 1
serv1.justinsdomain.com:8443 {
	log {
		output file caddy-Serv1.log
	}
	reverse_proxy :8080
	encode zstd gzip
	import headers
}
#file server 2
serv2.justinsdomain.com:8443 {
	import logging Serv2
	reverse_proxy :8081
	encode zstd gzip
	import headers
}

It’s not trash, it’s ANSI escape codes to set the text color.

I don’t understand what the problem is. How do you want it to look exactly?

First, my apologies, I didn’t have the correct Caddy config in the post, that will be fixed in a sec.

Without any formatting I get:
2023/03/16 00:17:36.210 info tls.cache.maintenance started background certificate maintenance {“cache”: “0xc0000f9ce0”}

with the formatting I get:
2023/07/22 18:26:07 e[34mINFOe[0m tls.cache.maintenance started background certificate maintenance {“cache”: “0xc00021c8c0”}

I want it to look like the first one, except with the time new time formatting.

(I also see now that the formatted output does not have logging level (warn, etc.), so I need that also.)

Well, I can’t edit the original post, so this is what the log directive was supposed to be:

log {
	output file caddy.log
	format console {
		time_format wall
		time_local
	}

You’ll also need to set level_format lowercase then. See log (Caddyfile directive) — Caddy Documentation

I just discovered that. When I added the level formatting, the superfluous characters went away. Thanks!

	format console {
		time_format wall
		time_local
		level_format upper
	}

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