1use std::fmt;
4use std::net::SocketAddr;
5use std::marker::PhantomData;
6
7use config::{NewErrorLog};
8
9#[derive(Debug)]
13pub enum ShutdownReason {
14 RequestStreamClosed,
19 AddressStreamClosed,
25 #[doc(hidden)]
26 __Nonexhaustive,
27}
28
29
30pub trait ErrorLog {
36 type ConnectionError;
38 type SinkError;
40 fn connection_error(&self, _addr: SocketAddr, _e: Self::ConnectionError) {}
42 fn sink_error(&self, _addr: SocketAddr, _e: Self::SinkError) {}
46 fn pool_shutting_down(&self, _reason: ShutdownReason) {}
48 fn pool_closed(&self) {}
50}
51
52
53pub struct WarnLogger;
55
56pub struct WarnLoggerInstance<C, S>(PhantomData<* const (C, S)>);
58
59impl<C, S> Clone for WarnLoggerInstance<C, S> {
60 fn clone(&self) -> Self {
61 WarnLoggerInstance(PhantomData)
62 }
63}
64
65impl<C: fmt::Display, S: fmt::Display> NewErrorLog<C, S> for WarnLogger {
66 type ErrorLog = WarnLoggerInstance<C, S>;
67 fn construct(self) -> Self::ErrorLog {
68 WarnLoggerInstance(PhantomData)
69 }
70}
71
72impl<C, S> ErrorLog for WarnLoggerInstance<C, S>
73 where C: fmt::Display,
74 S: fmt::Display,
75{
76 type ConnectionError = C;
77 type SinkError = S;
78 fn connection_error(&self, addr: SocketAddr, e: Self::ConnectionError) {
79 warn!("Connecting to {} failed: {}", addr, e);
80 }
81 fn sink_error(&self, addr: SocketAddr, e: Self::SinkError) {
82 warn!("Connection to {} errored: {}", addr, e);
83 }
84 fn pool_shutting_down(&self, reason: ShutdownReason) {
86 warn!("Shutting down connection pool: {}", reason);
87 }
88 fn pool_closed(&self) {
90 }
91}
92
93impl fmt::Display for ShutdownReason {
94 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95 use self::ShutdownReason::*;
96 f.write_str(match *self {
97 RequestStreamClosed => "request stream closed",
98 AddressStreamClosed => "address stream closed",
99 __Nonexhaustive => unreachable!(),
100 })
101 }
102}