Skip to content

Commit 35c67be

Browse files
committed
chore: defensive check for go-log slog bridge init
verify slog.Default() is go-log's bridge via duck typing before passing to gologshim, panics with clear error if go-log's init() didn't run
1 parent 0decc40 commit 35c67be

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/ipfs/kubo/start.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,18 @@ func init() {
5959
//
6060
// go-log's init() installs its slog bridge via slog.SetDefault().
6161
// We pass that handler to gologshim so go-libp2p loggers use it.
62-
gologshim.SetDefaultHandler(slog.Default().Handler())
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("slog.Default() is not go-log's bridge - go-log may not be properly initialized")
71+
}
72+
73+
gologshim.SetDefaultHandler(handler)
6374
}
6475

6576
// declared as a var for testing purposes.

0 commit comments

Comments
 (0)