Caddy Web 服务配置的 log 搞不定,问了 chatgpt,也无效,请教如何正确?

18次阅读

共计 942 个字符,预计需要花费 3 分钟才能阅读完成。

我是想 log 往 console 和 file 两个方向输出,配置目前是这样:

{admin off}
:31232 {
    root * /opt/caddy/www
    file_server
    header {Server ""}
    log {
        output file /opt/caddy/log/caddy.log {format single_field format {remote} - {user} [{when}] {method} {uri} {proto} {status} {size}
        }
    }
}

目前文件输出的日志格式是这样的:

2024/05/23 09:09:55.869 info    http.log.access.log0    handled request {"request": {"remote_ip": "192.168.18.188", "remote_port": "46604", "client_ip": "192.168.18.188", "proto": "HTTP/1.1", "method": "GET", "host": "192.168.18.188:51236", "uri": "/index.html", "headers": {"Accept": ["*/*"], "User-Agent": ["curl/7.74.0"]}}, "bytes_read": 0, "user_id": "","duration": 0.005588349,"size": 259,"status": 200,"resp_headers": {"Accept-Ranges": ["bytes"],"Content-Length": ["259"],"Server": [""], "Etag": [""sdvpdp77""], "Content-Type": ["text/html; charset=utf-8"], "Last-Modified": ["Wed, 22 May 2024 08:39:25 GMT"]}}

但我想要的格式是
UTC+8,{remote} – {user} [{when}] {method} {uri} {proto} {status} {size}
看了一轮官方文档,和 github 上的例子,还参考了 chatgpt 的答案,感觉应该是没写错,
但输出还是太多了,不知道问题在哪里了。。。。请教各位~~

正文完
 0