Skip to content

Commit 441297c

Browse files
authored
feat: support adding a logger to connection object (#726)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent aa8c86e commit 441297c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

connection.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"errors"
2828
"fmt"
2929
"io"
30+
"log/slog"
3031
"net"
3132
"sync"
3233
"time"
@@ -59,6 +60,7 @@ type Connection struct {
5960
networkMagic uint32
6061
server bool
6162
useNodeToNodeProto bool
63+
logger *slog.Logger
6264
muxer *muxer.Muxer
6365
errorChan chan error
6466
protoErrorChan chan error

connection_options.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2024 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
package ouroboros
1616

1717
import (
18+
"log/slog"
1819
"net"
1920

2021
"github.com/blinklabs-io/gouroboros/protocol/blockfetch"
@@ -66,6 +67,13 @@ func WithServer(server bool) ConnectionOptionFunc {
6667
}
6768
}
6869

70+
// WithLogger specifies the slog.Logger to use. This is empty by default
71+
func WithLogger(logger *slog.Logger) ConnectionOptionFunc {
72+
return func(c *Connection) {
73+
c.logger = logger
74+
}
75+
}
76+
6977
// WithNodeToNode specifies whether to use the node-to-node protocol. The default is to use node-to-client
7078
func WithNodeToNode(nodeToNode bool) ConnectionOptionFunc {
7179
return func(c *Connection) {

0 commit comments

Comments
 (0)