Signed-off-by: Jakob Borg <[email protected]>
This commit is contained in:
Jakob Borg committed 2026-11-16 08:59:44 +01:00
1 parent be42556744
commit c48cf7783e
2 files changed
+19

No files matched your search

+2
View File
@@ -12,6 +12,7 @@ import (
"sync"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p/gologshim"
"github.com/syncthing/syncthing/internal/slogutil"
"go.uber.org/zap/zapcore"
)
@@ -26,6 +27,7 @@ func setupLibraryLogging() {
// the normal Syncthing log stream and support bundles. The slog handler
// still controls whether debug records are emitted.
logging.SetPrimaryCore(libraryLogCore{})
gologshim.SetDefaultHandler(logging.SlogHandler())
for _, system := range []string{"dht", "dht/RtRefreshManager", "swarm2", "autonat"} {
_ = logging.SetLogLevel(system, "debug")
}
+17
View File
@@ -13,6 +13,7 @@ import (
"strings"
"testing"
"github.com/libp2p/go-libp2p/gologshim"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@@ -45,3 +46,19 @@ func TestLibraryLogCore(t *testing.T) {
t.Fatal("verbose library info should require debug logging")
}
}
// libp2p's native slog loggers need an explicit bridge in addition to the
// older DHT dependency's Zap loggers.
func TestLibraryLogShim(t *testing.T) {
var output bytes.Buffer
previous := slog.Default()
slog.SetDefault(slog.New(slog.NewTextHandler(&output, &slog.HandlerOptions{Level: slog.LevelDebug})))
t.Cleanup(func() { slog.SetDefault(previous) })
setupLibraryLogging()
gologshim.Logger("autonat").Debug("test dialback result", "peer", "test-peer", "err", errors.New("dial failed"))
for _, want := range []string{"test dialback result", "test-peer", "dial failed", "autonat"} {
if !strings.Contains(output.String(), want) {
t.Errorf("missing %q in %s", want, output.String())
}
}
}