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

127 天前
 qazwsxkevin

我是想 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 的答案, 感觉应该是没写错,
但输出还是太多了,不知道问题在哪里了。。。。请教各位~~

511 次点击
所在节点    问与答
2 条回复
zsj1029
126 天前
我已经放弃了,官网例子太少全靠猜,21 年就不维护了
qazwsxkevin
126 天前
@zsj1029 #1 你对,我准备下午五点左右就放弃,改用 lightted 试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1043343

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX