From 0a315c253ca170a6e7e181ec13489d256f811bd0 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 23 Sep 2018 11:37:26 +0200 Subject: [PATCH] Provide generic logging interface --- client.go | 5 +++++ serial.go | 3 +-- tcpclient.go | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index ac3ee2e..4b69dc2 100644 --- a/client.go +++ b/client.go @@ -9,6 +9,11 @@ import ( "fmt" ) +// logger is the interface to the required logging functions +type logger interface { + Printf(format string, v ...interface{}) +} + // ClientHandler is the interface that groups the Packager and Transporter methods. type ClientHandler interface { Packager diff --git a/serial.go b/serial.go index 7d14c67..01e2b9a 100644 --- a/serial.go +++ b/serial.go @@ -6,7 +6,6 @@ package modbus import ( "io" - "log" "sync" "time" @@ -24,7 +23,7 @@ type serialPort struct { // Serial port configuration. serial.Config - Logger *log.Logger + Logger logger IdleTimeout time.Duration mu sync.Mutex diff --git a/tcpclient.go b/tcpclient.go index 4e53c73..5dcc01b 100644 --- a/tcpclient.go +++ b/tcpclient.go @@ -8,7 +8,6 @@ import ( "encoding/binary" "fmt" "io" - "log" "net" "sync" "sync/atomic" @@ -135,7 +134,7 @@ type tcpTransporter struct { // Idle timeout to close the connection IdleTimeout time.Duration // Transmission logger - Logger *log.Logger + Logger logger // TCP connection mu sync.Mutex