V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
qazwsxkevin
V2EX  ›  问与答

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

  •  
  •   qazwsxkevin · 24 天前 · 362 次点击

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

    2 条回复    2024-05-24 14:26:43 +08:00
    zsj1029
        1
    zsj1029  
       23 天前
    我已经放弃了,官网例子太少全靠猜,21 年就不维护了
    qazwsxkevin
        2
    qazwsxkevin  
    OP
       23 天前
    @zsj1029 #1 你对,我准备下午五点左右就放弃,改用 lightted 试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2588 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 14:50 · PVG 22:50 · LAX 07:50 · JFK 10:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.