mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 08:31:55 +08:00
refactor(internal/handler, internal/middleware): improve access log format and content
This commit is contained in:
parent
3c380ef5e9
commit
eda76c1683
@ -165,9 +165,17 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// 记录访问日志
|
||||
log.Printf("[%s] %s %s%s -> %s -> %d (%s) [%v]",
|
||||
utils.GetClientIP(r), r.Method, r.URL.Path, utils.GetRequestSource(r), targetURL,
|
||||
resp.StatusCode, utils.FormatBytes(bytesCopied), time.Since(startTime))
|
||||
log.Printf("%s | %3d | %12s | %15s | %-6s | %-50s -> %s%s",
|
||||
time.Now().Format("2006/01/02 - 15:04:05"), // 时间戳
|
||||
resp.StatusCode, // 状态码,占3位
|
||||
time.Since(startTime), // 处理时间,占12位
|
||||
utils.GetClientIP(r), // IP地址,占15位
|
||||
r.Method, // HTTP方法,左对齐占6位
|
||||
r.URL.Path, // 请求路径,左对齐占50位
|
||||
targetURL, // 目标URL
|
||||
utils.GetRequestSource(r), // 请求来源
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func copyHeader(dst, src http.Header) {
|
||||
|
@ -78,9 +78,16 @@ func FixedPathProxyMiddleware(configs []config.FixedPathConfig) func(http.Handle
|
||||
}
|
||||
|
||||
// 记录成功的请求
|
||||
log.Printf("[%s] %s %s%s -> %s -> %d (%s) [%v]",
|
||||
utils.GetClientIP(r), r.Method, r.URL.Path, utils.GetRequestSource(r), targetURL,
|
||||
resp.StatusCode, utils.FormatBytes(bytesCopied), time.Since(startTime))
|
||||
log.Printf("%s | %3d | %10s | %12s | %15s | %-6s | %-50s -> %-50s",
|
||||
time.Now().Format("2006/01/02 - 15:04:05"), // 时间戳
|
||||
resp.StatusCode, // 状态码
|
||||
utils.FormatBytes(bytesCopied), // 传输大小
|
||||
time.Since(startTime), // 处理时间
|
||||
utils.GetClientIP(r), // IP地址
|
||||
r.Method, // HTTP方法
|
||||
r.URL.Path, // 原始请求路径
|
||||
targetURL, // 目标URL
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user