1. Caddy version (caddy version
):
2.5
2. How I run Caddy:
currently use localhost
a. System environment:
Windows 11
b. Command:
caddy start
c. Service/unit/compose file:
N/A
d. My complete Caddyfile or JSON config:
{
debug
}
:80, localhost, http:// {
root * B:/tests
file_server browse
log {
output file site.log
format json
}
}
3. The problem I’m having:
I went through the documentation for format-modules and couldn’t figure out how to customize the information that appears in the log. I only wanted the most basic information, just URI and referrer, and I know that the ts, level, logger, and msg fields also get included. I bolded the fields that I wanted to keep in the output below.
I saw documentation for calling the log formatter (like json) and saw the json documentation for log in the link I included below, but I have no idea how to combine the two to get any customization. I tried compiling with the transform-encoder module as well and couldn’t get it to work.
If you could provide an example of what I should include in my caddyfile that would help so much. Thanks for your time.
4. Error messages and/or full log output:
{“level”:“info”,“ts”:1650378795.636168,“logger”:“http.log.access.log0”,“msg”:"handled request",“request”:{“remote_ip”:"::1",“remote_port”:“63751”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“localhost”,“uri”:"/folder%202/",“headers”:{“Upgrade-Insecure-Requests”:[“1”],“User-Agent”:[“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36”],“Accept”:[“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”],“Accept-Language”:[“en-US,en;q=0.9”],“Accept-Encoding”:[“gzip, deflate, br”],“Sec-Gpc”:[“1”],“Sec-Fetch-Site”:[“same-origin”],“Sec-Fetch-Mode”:[“navigate”],“Sec-Fetch-User”:["?1"],“Sec-Fetch-Dest”:[“document”],“Referer”:[“https://localhost/folder%202/”]},“tls”:{“resumed”:false,“version”:772,“cipher_suite”:4865,“proto”:“h2”,“server_name”:“localhost”}},“user_id”:"",“duration”:0.0013091,“size”:15645,“status”:200,“resp_headers”:{“Server”:[“Caddy”],“Content-Type”:[“text/html; charset=utf-8”]}}
{“level”:“info”,“ts”:1650378800.5284705,“logger”:“http.log.access.log0”,“msg”:"handled request",“request”:{“remote_ip”:"::1",“remote_port”:“63751”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“localhost”,“uri”:"/folder%202/New%20Bitmap%20image.bmp",“headers”:{“User-Agent”:[“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36”],“Sec-Gpc”:[“1”],“Sec-Fetch-Mode”:[“navigate”],“Referer”:[“https://localhost/folder%202/”],“Accept-Encoding”:[“gzip, deflate, br”],“Upgrade-Insecure-Requests”:[“1”],“Accept”:[“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”],“Sec-Fetch-Site”:[“same-origin”],“Sec-Fetch-User”:["?1"],“Sec-Fetch-Dest”:[“document”],“Accept-Language”:[“en-US,en;q=0.9”]},“tls”:{“resumed”:false,“version”:772,“cipher_suite”:4865,“proto”:“h2”,“server_name”:“localhost”}},“user_id”:"",“duration”:0.0210946,“size”:0,“status”:200,“resp_headers”:{“Content-Type”:[“image/bmp”],“Last-Modified”:[“Fri, 08 Apr 2022 18:23:07 GMT”],“Accept-Ranges”:[“bytes”],“Content-Length”:[“0”],“Server”:[“Caddy”],“Etag”:["“ra19qj0"”]}}
5. What I already tried:
I tried using a build with the transform-encoder but didn’t get anywhere with that. Here was the config I tried with that:
log {
output file site.log
format formatted “{ts} {level} {request>uri}”
}