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