style(internal/handler, internal/middleware): Refactor logging format for consistency and clarity

This commit is contained in:
wood chen 2024-11-03 08:33:38 +08:00
parent eda76c1683
commit 073d364695
2 changed files with 17 additions and 17 deletions

View File

@ -165,15 +165,15 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// 记录访问日志 // 记录访问日志
log.Printf("%s | %3d | %12s | %15s | %-6s | %-50s -> %s%s", log.Printf("| %-6s | %3d | %12s | %15s | %10s | %-30s | %-50s -> %s",
time.Now().Format("2006/01/02 - 15:04:05"), // 时间戳 r.Method, // HTTP方法左对齐占6位
resp.StatusCode, // 状态码占3位 resp.StatusCode, // 状态码占3位
time.Since(startTime), // 处理时间占12位 time.Since(startTime), // 处理时间占12位
utils.GetClientIP(r), // IP地址占15位 utils.GetClientIP(r), // IP地址占15位
r.Method, // HTTP方法左对齐占6 utils.FormatBytes(bytesCopied), // 传输大小占10
r.URL.Path, // 请求路径左对齐占50位 utils.GetRequestSource(r), // 请求来源
targetURL, // 目标URL r.URL.Path, // 请求路径左对齐占50位
utils.GetRequestSource(r), // 请求来源 targetURL, // 目标URL
) )
} }

View File

@ -78,14 +78,14 @@ func FixedPathProxyMiddleware(configs []config.FixedPathConfig) func(http.Handle
} }
// 记录成功的请求 // 记录成功的请求
log.Printf("%s | %3d | %10s | %12s | %15s | %-6s | %-50s -> %-50s", log.Printf("| %-6s | %3d | %12s | %15s | %10s | %-30s | %-50s -> %s",
time.Now().Format("2006/01/02 - 15:04:05"), // 时间戳 r.Method, // HTTP方法左对齐占6位
resp.StatusCode, // 状态码 resp.StatusCode, // 状态码占3位
utils.FormatBytes(bytesCopied), // 传输大小 time.Since(startTime), // 处理时间占12位
time.Since(startTime), // 处理时间 utils.GetClientIP(r), // IP地址占15位
utils.GetClientIP(r), // IP地址 utils.FormatBytes(bytesCopied), // 传输大小占10位
r.Method, // HTTP方法 utils.GetRequestSource(r), // 请求来源
r.URL.Path, // 原始请求路径 r.URL.Path, // 请求路径左对齐占50位
targetURL, // 目标URL targetURL, // 目标URL
) )