pub trait Fallback {
// Provided method
fn fallback(&self, error: &ServiceError, message: &Message) { ... }
}Expand description
A strategy for handling log delivery failures.
The Fallback trait defines how the system should react when a log service
is unable to process a message after exhausting all retry attempts.
§Use Cases
- Local Logging: Writing failed logs to
stdout,stderr, or a local file. - Alerting: Triggering a secondary notification system if critical logs are lost.
- Buffering: Storing failed messages in a persistent queue for later recovery.
§Thread Safety
Since the worker thread calls this trait’s method, implementations must be thread-safe if they involve shared state.
Provided Methods§
Sourcefn fallback(&self, error: &ServiceError, message: &Message)
fn fallback(&self, error: &ServiceError, message: &Message)
Handles a message that could not be delivered to the primary service.
This method is invoked by the background worker when a ServiceError occurs
that cannot be recovered through retries.
§Default Implementation
The default implementation prints a formatted critical error message to stderr. It includes:
- The specific
ServiceErrordescription. - An RFC3339-compliant timestamp with nanosecond precision.
- The log level and the original message content.
This ensures that even if the remote collector is unreachable, the logs are preserved in the system’s standard error stream.
§Parameters
error: The specific error that caused the delivery failure.message: The original log message that failed to be delivered.