Fix nanoswitch logging after logtree refactor
The LogTree refactor left nanoswitch without a way to sink its logs as it doesn't have
a gRPC endpoint to read them from and logtree doesn't output to any stdout/stderr by default.
This adds a simple sink similar to what's currently used the node code.
Test Plan: Manually tested
X-Origin-Diff: phab/D672
GitOrigin-RevId: 8698f9f920f36adf11fa1ef34a47723514eaa665
diff --git a/metropolis/test/nanoswitch/nanoswitch.go b/metropolis/test/nanoswitch/nanoswitch.go
index cba4e50..2569ab6 100644
--- a/metropolis/test/nanoswitch/nanoswitch.go
+++ b/metropolis/test/nanoswitch/nanoswitch.go
@@ -40,6 +40,7 @@
common "git.monogon.dev/source/nexantic.git/metropolis/node"
"git.monogon.dev/source/nexantic.git/metropolis/node/common/supervisor"
+ "git.monogon.dev/source/nexantic.git/metropolis/node/core/logtree"
"git.monogon.dev/source/nexantic.git/metropolis/node/core/network/dhcp4c"
dhcpcb "git.monogon.dev/source/nexantic.git/metropolis/node/core/network/dhcp4c/callback"
"git.monogon.dev/source/nexantic.git/metropolis/test/launch"
@@ -179,6 +180,16 @@
}
func main() {
+ lt := logtree.New()
+ reader, err := lt.Read("", logtree.WithChildren(), logtree.WithStream())
+ if err != nil {
+ panic(fmt.Errorf("could not set up root log reader: %v", err))
+ }
+ go func() {
+ for p := range reader.Stream {
+ fmt.Fprintf(os.Stderr, "%s\n", p.String())
+ }
+ }()
supervisor.New(context.Background(), func(ctx context.Context) error {
logger := supervisor.Logger(ctx)
logger.Info("Starting NanoSwitch, a tiny TOR switch emulator")
@@ -296,6 +307,6 @@
supervisor.Signal(ctx, supervisor.SignalHealthy)
supervisor.Signal(ctx, supervisor.SignalDone)
return nil
- })
+ }, supervisor.WithExistingLogtree(lt))
select {}
}