mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 06:56:36 +08:00
chore: improve log print
This commit is contained in:
@@ -50,18 +50,7 @@ func loggerMiddleware() gin.HandlerFunc {
|
||||
// 排除健康检查接口
|
||||
healthPath := config.Config.App.APIPrefix + "/health"
|
||||
if c.Request.URL.Path != healthPath {
|
||||
logger.InfoF(
|
||||
ctx,
|
||||
"[LoggerMiddleware] %s %s\nStartTime: %s\nEndTime: %s\nLatency: %d\nClientIP: %s\nResponse: %d %d",
|
||||
c.Request.Method,
|
||||
path,
|
||||
start.Format(time.RFC3339),
|
||||
end.Format(time.RFC3339),
|
||||
latency.Milliseconds(),
|
||||
c.ClientIP(),
|
||||
c.Writer.Status(),
|
||||
c.Writer.Size(),
|
||||
)
|
||||
logRequest(ctx, c, path, start, end, latency)
|
||||
}
|
||||
|
||||
// 设置 Span 状态
|
||||
@@ -72,6 +61,29 @@ func loggerMiddleware() gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func logRequest(ctx context.Context, c *gin.Context, path string, start, end time.Time, latency time.Duration) {
|
||||
format := "[LoggerMiddleware] %s %s\nStartTime: %s\nEndTime: %s\nLatency: %d\nClientIP: %s\nResponse: %d %d"
|
||||
args := []interface{}{
|
||||
c.Request.Method,
|
||||
path,
|
||||
start.Format(time.RFC3339),
|
||||
end.Format(time.RFC3339),
|
||||
latency.Milliseconds(),
|
||||
c.ClientIP(),
|
||||
c.Writer.Status(),
|
||||
c.Writer.Size(),
|
||||
}
|
||||
|
||||
switch {
|
||||
case c.Writer.Status() >= http.StatusInternalServerError:
|
||||
logger.ErrorF(ctx, format, args...)
|
||||
case c.Writer.Status() >= http.StatusBadRequest:
|
||||
logger.WarnF(ctx, format, args...)
|
||||
default:
|
||||
logger.DebugF(ctx, format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func isOriginAllowed(ctx context.Context, origin string) bool {
|
||||
sc, err := repository.GetSystemConfigByKey(ctx, model.ConfigKeyServerAddress)
|
||||
if err != nil || sc.Value == "" {
|
||||
|
||||
Reference in New Issue
Block a user