refactor: enhance error logging in writeLogLines to respect circuit breaker state

This commit is contained in:
Marvin Zhang
2025-09-12 14:34:27 +08:00
parent c0e230e5d8
commit 14a94ff798

View File

@@ -54,6 +54,10 @@ func (r *Runner) writeLogLines(lines []string) {
case <-r.ctx.Done():
return
default:
// Only log the error if circuit breaker allows it to prevent flooding
if r.isLogCircuitClosed() {
r.Errorf("error sending log lines: %v", err)
}
// Record failure and open circuit breaker if needed
r.recordLogFailure()
// Mark connection as unhealthy for reconnection
@@ -180,7 +184,7 @@ func (r *Runner) recordLogFailure() {
r.logConnHealthy = false
r.logCircuitOpenTime = time.Now()
// Log this through standard logger only (not through writeLogLines to avoid recursion)
r.Logger.Warn(fmt.Sprintf("log circuit breaker opened after %d failures, suppressing log sends for %v",
r.Logger.Warn(fmt.Sprintf("log circuit breaker opened after %d failures, suppressing log sends for %v",
r.logFailureCount, r.logCircuitOpenDuration))
}
}