我是想 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 的答案, 感觉应该是没写错,
但输出还是太多了,不知道问题在哪里了。。。。请教各位~~
![]() |
1
zsj1029 102 天前
我已经放弃了,官网例子太少全靠猜,21 年就不维护了
|
2
qazwsxkevin OP @zsj1029 #1 你对,我准备下午五点左右就放弃,改用 lightted 试试
|