refactor: extract skip/level helpers from logJikanCache
This commit is contained in:
@@ -149,25 +149,43 @@ func jikanTraceEnabled() bool {
|
|||||||
return traceEnabled
|
return traceEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func logJikanCache(cacheKey string, source string, startedAt time.Time, err error) {
|
func shouldSkipJikanCacheLog(source string, duration time.Duration, err error) bool {
|
||||||
duration := time.Since(startedAt)
|
if jikanTraceEnabled() || err != nil {
|
||||||
if !jikanTraceEnabled() && err == nil && source == "fresh" && duration < 50*time.Millisecond {
|
return false
|
||||||
return
|
|
||||||
}
|
|
||||||
if !jikanTraceEnabled() && err == nil && source == "refresh" && duration < jikanSlowLogThreshold {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
level := observability.LogLevelInfo
|
if source == "fresh" {
|
||||||
|
return duration < 50*time.Millisecond
|
||||||
|
}
|
||||||
|
|
||||||
|
if source == "refresh" {
|
||||||
|
return duration < jikanSlowLogThreshold
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func jikanCacheLogLevel(source string, err error) observability.LogLevel {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
level = observability.LogLevelError
|
return observability.LogLevelError
|
||||||
} else if source != "fresh" && source != "refresh" {
|
}
|
||||||
|
|
||||||
|
if source != "fresh" && source != "refresh" {
|
||||||
// Stale reads are expected sometimes, but worth tracking in logs.
|
// Stale reads are expected sometimes, but worth tracking in logs.
|
||||||
level = observability.LogLevelWarn
|
return observability.LogLevelWarn
|
||||||
|
}
|
||||||
|
|
||||||
|
return observability.LogLevelInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func logJikanCache(cacheKey string, source string, startedAt time.Time, err error) {
|
||||||
|
duration := time.Since(startedAt)
|
||||||
|
if shouldSkipJikanCacheLog(source, duration, err) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
observability.LogJSON(
|
observability.LogJSON(
|
||||||
level,
|
jikanCacheLogLevel(source, err),
|
||||||
"jikan_cache",
|
"jikan_cache",
|
||||||
"jikan",
|
"jikan",
|
||||||
"",
|
"",
|
||||||
|
|||||||
Reference in New Issue
Block a user