fix: add warn levels to observability logs
This commit is contained in:
@@ -158,6 +158,9 @@ func logJikanCache(cacheKey string, source string, startedAt time.Time, err erro
|
||||
level := observability.LogLevelInfo
|
||||
if err != nil {
|
||||
level = observability.LogLevelError
|
||||
} else if source != "fresh" && source != "refresh" {
|
||||
// Stale reads are expected sometimes, but worth tracking in logs.
|
||||
level = observability.LogLevelWarn
|
||||
}
|
||||
|
||||
observability.LogJSON(
|
||||
@@ -181,8 +184,10 @@ func logJikanUpstream(urlStr string, statusCode int, attempts int, startedAt tim
|
||||
}
|
||||
|
||||
level := observability.LogLevelInfo
|
||||
if err != nil || statusCode >= http.StatusBadRequest {
|
||||
if err != nil || statusCode >= http.StatusInternalServerError {
|
||||
level = observability.LogLevelError
|
||||
} else if statusCode == http.StatusTooManyRequests || statusCode >= http.StatusBadRequest {
|
||||
level = observability.LogLevelWarn
|
||||
}
|
||||
|
||||
observability.LogJSON(
|
||||
|
||||
@@ -23,8 +23,16 @@ func RequestLogger(metrics *observability.Metrics) gin.HandlerFunc {
|
||||
duration := time.Since(start)
|
||||
metrics.ObserveHTTPRequest(c.Request.Method, route, c.Writer.Status(), duration)
|
||||
|
||||
level := observability.LogLevelInfo
|
||||
status := c.Writer.Status()
|
||||
if status >= 500 {
|
||||
level = observability.LogLevelError
|
||||
} else if status >= 400 {
|
||||
level = observability.LogLevelWarn
|
||||
}
|
||||
|
||||
observability.LogJSON(
|
||||
observability.LogLevelInfo,
|
||||
level,
|
||||
"http_request",
|
||||
"http",
|
||||
"",
|
||||
@@ -33,7 +41,7 @@ func RequestLogger(metrics *observability.Metrics) gin.HandlerFunc {
|
||||
"route": route,
|
||||
"path": path,
|
||||
"query": query,
|
||||
"status": c.Writer.Status(),
|
||||
"status": status,
|
||||
"duration_ms": float64(duration.Microseconds()) / 1000,
|
||||
"bytes": c.Writer.Size(),
|
||||
"client_ip": c.ClientIP(),
|
||||
|
||||
Reference in New Issue
Block a user