mirror of
https://github.com/syncthing/syncthing.git
synced 2026-12-05 08:12:37 -08:00
2 files changed
+19
No files matched your search
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user