From 99d4f1c6bf76d7b4cd9617d9a97c4862e5dd5888 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Sat, 28 Sep 2024 11:13:16 -0400 Subject: [PATCH] feat: support adding a logger to connection object Signed-off-by: Chris Gianelloni --- connection.go | 2 ++ connection_options.go | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/connection.go b/connection.go index 0287ffa6..7c7b3b2c 100644 --- a/connection.go +++ b/connection.go @@ -27,6 +27,7 @@ import ( "errors" "fmt" "io" + "log/slog" "net" "sync" "time" @@ -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 diff --git a/connection_options.go b/connection_options.go index d7b42917..57465dca 100644 --- a/connection_options.go +++ b/connection_options.go @@ -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. @@ -15,6 +15,7 @@ package ouroboros import ( + "log/slog" "net" "github.com/blinklabs-io/gouroboros/protocol/blockfetch" @@ -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) {