Skip to content

Commit

Permalink
feat: support adding a logger to connection object
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 committed Sep 28, 2024
1 parent aa8c86e commit 99d4f1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net"
"sync"
"time"
Expand Down Expand Up @@ -59,6 +60,7 @@ type Connection struct {
networkMagic uint32
server bool
useNodeToNodeProto bool
logger *slog.Logger
muxer *muxer.Muxer
errorChan chan error
protoErrorChan chan error
Expand Down
10 changes: 9 additions & 1 deletion connection_options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2024 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package ouroboros

import (
"log/slog"
"net"

"github.com/blinklabs-io/gouroboros/protocol/blockfetch"
Expand Down Expand Up @@ -66,6 +67,13 @@ func WithServer(server bool) ConnectionOptionFunc {
}
}

// WithLogger specifies the slog.Logger to use. This is empty by default
func WithLogger(logger *slog.Logger) ConnectionOptionFunc {
return func(c *Connection) {
c.logger = logger
}
}

// WithNodeToNode specifies whether to use the node-to-node protocol. The default is to use node-to-client
func WithNodeToNode(nodeToNode bool) ConnectionOptionFunc {
return func(c *Connection) {
Expand Down

0 comments on commit 99d4f1c

Please sign in to comment.