Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Package modbus provides a client for MODBUS TCP and RTU/ASCII.
package modbus

import (
"context"
"fmt"
)

Expand Down Expand Up @@ -116,3 +117,15 @@ type Connector interface {
Connect() error
Close() error
}

// Logger is an interface to define custom loggers
type Logger interface {
Debug(string, ...any)
DebugContext(context.Context, string, ...any)
Info(string, ...any)
InfoContext(context.Context, string, ...any)
Warn(string, ...any)
WarnContext(context.Context, string, ...any)
Error(string, ...any)
ErrorContext(context.Context, string, ...any)
}
3 changes: 1 addition & 2 deletions rtu_over_udp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package modbus
import (
"fmt"
"io"
logger "log/slog"
"net"
"sync"
)
Expand Down Expand Up @@ -46,7 +45,7 @@ type rtuUDPTransporter struct {
// Connect string
Address string
// Transmission logger
Logger *logger.Logger
Logger Logger

// UDP connection
mu sync.Mutex
Expand Down
3 changes: 1 addition & 2 deletions serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
"log/slog"
"sync"
"time"

Expand All @@ -26,7 +25,7 @@ type serialPort struct {
// Serial port configuration.
serial.Config

Logger *slog.Logger
Logger Logger
IdleTimeout time.Duration

mu sync.Mutex
Expand Down
3 changes: 1 addition & 2 deletions tcpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/binary"
"fmt"
"io"
"log/slog"
"net"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -138,7 +137,7 @@ type tcpTransporter struct {
// Silent period after successful connection
ConnectDelay time.Duration
// Transmission logger
Logger *slog.Logger
Logger Logger

// TCP connection
mu sync.Mutex
Expand Down