From df82184cee45c0dbbf859f74c78fd7aba0ba350e Mon Sep 17 00:00:00 2001 From: wbflooksky Date: Mon, 20 Feb 2023 22:37:09 +0800 Subject: [PATCH] feat: The abstract log interface facilitates external access to logs. --- config.go | 3 +-- logging.go | 4 ++++ memberlist.go | 2 +- net_transport.go | 5 ++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 3d9100153..93fa25fef 100644 --- a/config.go +++ b/config.go @@ -6,7 +6,6 @@ package memberlist import ( "fmt" "io" - "log" "net" "os" "strings" @@ -224,7 +223,7 @@ type Config struct { // this for the internal logger. If Logger is not set, it will fall back to the // behavior for using LogOutput. You cannot specify both LogOutput and Logger // at the same time. - Logger *log.Logger + Logger Logger // Size of Memberlist's internal channel which handles UDP messages. The // size of this determines the size of the queue which Memberlist will keep diff --git a/logging.go b/logging.go index f9d5f0fb2..c5b7937cf 100644 --- a/logging.go +++ b/logging.go @@ -8,6 +8,10 @@ import ( "net" ) +type Logger interface { + Printf(format string, v ...interface{}) +} + func LogAddress(addr net.Addr) string { if addr == nil { return "from=" diff --git a/memberlist.go b/memberlist.go index 6d5f4a703..ad706c22e 100644 --- a/memberlist.go +++ b/memberlist.go @@ -80,7 +80,7 @@ type Memberlist struct { broadcasts *TransmitLimitedQueue - logger *log.Logger + logger Logger // metricLabels is the slice of labels to put on all emitted metrics metricLabels []metrics.Label diff --git a/net_transport.go b/net_transport.go index 5d3a8f4c5..17ae6c8f2 100644 --- a/net_transport.go +++ b/net_transport.go @@ -7,7 +7,6 @@ import ( "bytes" "fmt" "io" - "log" "net" "sync" "sync/atomic" @@ -37,7 +36,7 @@ type NetTransportConfig struct { BindPort int // Logger is a logger for operator messages. - Logger *log.Logger + Logger Logger // MetricLabels is a map of optional labels to apply to all metrics // emitted by this transport. @@ -50,7 +49,7 @@ type NetTransport struct { config *NetTransportConfig packetCh chan *Packet streamCh chan net.Conn - logger *log.Logger + logger Logger wg sync.WaitGroup tcpListeners []*net.TCPListener udpListeners []*net.UDPConn