Skip to content

Commit ef7d8d1

Browse files
committed
chore: use go-log SlogHandler() for go-libp2p integration
update to go-log v2.8.3-0.20251105191458-101e2c1ac85a which provides SlogHandler() function for explicit wiring. simplify start.go by using logging.SlogHandler() directly instead of slog.Default().Handler() with duck-typing verification. more explicit and works even when GOLOG_CAPTURE_DEFAULT_SLOG=false.
1 parent fec2a37 commit ef7d8d1

File tree

7 files changed

+12
-24
lines changed

7 files changed

+12
-24
lines changed

cmd/ipfs/kubo/start.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11-
"log/slog"
1211
"net"
1312
"net/http"
1413
"os"
@@ -57,20 +56,9 @@ func init() {
5756
// This ensures go-libp2p logs integrate with go-log's formatting
5857
// and dynamic level control (e.g., `ipfs log level libp2p-swarm debug`).
5958
//
60-
// go-log's init() installs its slog bridge via slog.SetDefault().
61-
// We pass that handler to gologshim so go-libp2p loggers use it.
62-
handler := slog.Default().Handler()
63-
64-
// Verify that slog.Default() is go-log's bridge via duck typing.
65-
// This catches misconfigurations where go-log's init() didn't run.
66-
type goLogBridge interface {
67-
GoLogBridge()
68-
}
69-
if _, ok := handler.(goLogBridge); !ok {
70-
panic("aborting startup: slog.Default() is not go-log's bridge, go-libp2p logs would be missing due to incorrect wiring")
71-
}
72-
73-
gologshim.SetDefaultHandler(handler)
59+
// Use SlogHandler() to get go-log's bridge directly.
60+
// This works even when GOLOG_CAPTURE_DEFAULT_SLOG=false.
61+
gologshim.SetDefaultHandler(logging.SlogHandler())
7462
}
7563

7664
// declared as a var for testing purposes.

docs/examples/kubo-as-a-library/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/ipfs/go-ipld-format v0.6.3 // indirect
9494
github.com/ipfs/go-ipld-git v0.1.1 // indirect
9595
github.com/ipfs/go-ipld-legacy v0.2.2 // indirect
96-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49 // indirect
96+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a // indirect
9797
github.com/ipfs/go-metrics-interface v0.3.0 // indirect
9898
github.com/ipfs/go-peertaskqueue v0.8.2 // indirect
9999
github.com/ipfs/go-test v0.2.3 // indirect

docs/examples/kubo-as-a-library/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ github.com/ipfs/go-ipld-git v0.1.1/go.mod h1:+VyMqF5lMcJh4rwEppV0e6g4nCCHXThLYYD
349349
github.com/ipfs/go-ipld-legacy v0.2.2 h1:DThbqCPVLpWBcGtU23KDLiY2YRZZnTkXQyfz8aOfBkQ=
350350
github.com/ipfs/go-ipld-legacy v0.2.2/go.mod h1:hhkj+b3kG9b2BcUNw8IFYAsfeNo8E3U7eYlWeAOPyDU=
351351
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
352-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49 h1:IeFkT7voVHOd7KsTTfXlIh4WIV9m7+UYLFuxLp6a5PM=
353-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
352+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a h1:ZtrWQty1MnTu5sJFWpX01KIAEgqmyVphKTmdIbuspm0=
353+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
354354
github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6q/JR9V40TU=
355355
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
356356
github.com/ipfs/go-peertaskqueue v0.8.2 h1:PaHFRaVFdxQk1Qo3OKiHPYjmmusQy7gKQUaL8JDszAU=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ require (
3939
github.com/ipfs/go-ipld-format v0.6.3
4040
github.com/ipfs/go-ipld-git v0.1.1
4141
github.com/ipfs/go-ipld-legacy v0.2.2
42-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49
42+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a
4343
github.com/ipfs/go-metrics-interface v0.3.0
4444
github.com/ipfs/go-metrics-prometheus v0.1.0
4545
github.com/ipfs/go-test v0.2.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ github.com/ipfs/go-ipld-git v0.1.1/go.mod h1:+VyMqF5lMcJh4rwEppV0e6g4nCCHXThLYYD
416416
github.com/ipfs/go-ipld-legacy v0.2.2 h1:DThbqCPVLpWBcGtU23KDLiY2YRZZnTkXQyfz8aOfBkQ=
417417
github.com/ipfs/go-ipld-legacy v0.2.2/go.mod h1:hhkj+b3kG9b2BcUNw8IFYAsfeNo8E3U7eYlWeAOPyDU=
418418
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
419-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49 h1:IeFkT7voVHOd7KsTTfXlIh4WIV9m7+UYLFuxLp6a5PM=
420-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
419+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a h1:ZtrWQty1MnTu5sJFWpX01KIAEgqmyVphKTmdIbuspm0=
420+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
421421
github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6q/JR9V40TU=
422422
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
423423
github.com/ipfs/go-metrics-prometheus v0.1.0 h1:bApWOHkrH3VTBHzTHrZSfq4n4weOZDzZFxUXv+HyKcA=

test/dependencies/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd
99
github.com/golangci/golangci-lint v1.64.8
1010
github.com/ipfs/go-cidutil v0.1.0
11-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49
11+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a
1212
github.com/ipfs/go-test v0.2.3
1313
github.com/ipfs/hang-fds v0.1.0
1414
github.com/ipfs/iptb v1.4.1

test/dependencies/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ github.com/ipfs/go-ipld-format v0.6.3 h1:9/lurLDTotJpZSuL++gh3sTdmcFhVkCwsgx2+rA
364364
github.com/ipfs/go-ipld-format v0.6.3/go.mod h1:74ilVN12NXVMIV+SrBAyC05UJRk0jVvGqdmrcYZvCBk=
365365
github.com/ipfs/go-ipld-legacy v0.2.2 h1:DThbqCPVLpWBcGtU23KDLiY2YRZZnTkXQyfz8aOfBkQ=
366366
github.com/ipfs/go-ipld-legacy v0.2.2/go.mod h1:hhkj+b3kG9b2BcUNw8IFYAsfeNo8E3U7eYlWeAOPyDU=
367-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49 h1:IeFkT7voVHOd7KsTTfXlIh4WIV9m7+UYLFuxLp6a5PM=
368-
github.com/ipfs/go-log/v2 v2.8.3-0.20251104190326-eea1e4119c49/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
367+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a h1:ZtrWQty1MnTu5sJFWpX01KIAEgqmyVphKTmdIbuspm0=
368+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
369369
github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6q/JR9V40TU=
370370
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
371371
github.com/ipfs/go-peertaskqueue v0.8.2 h1:PaHFRaVFdxQk1Qo3OKiHPYjmmusQy7gKQUaL8JDszAU=

0 commit comments

Comments
 (0)