metropolis/resolver: use logging.Leveled
This moves the resover client library to use logging.Leveled instead of
an ad-hoc logger interface.
By now having multiple level of logs, and by defaulting metroctl to show
errors and warnings, this should fix #302.
Change-Id: I7cae1cf1be377ec824ad46ea1da1b23b46e01903
Reviewed-on: https://review.monogon.dev/c/monogon/+/3432
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/cli/metroctl/main.go b/metropolis/cli/metroctl/main.go
index cdc4947..fcdbccd 100644
--- a/metropolis/cli/metroctl/main.go
+++ b/metropolis/cli/metroctl/main.go
@@ -3,12 +3,13 @@
import (
"context"
"crypto/x509"
- "log"
+ "os"
"path/filepath"
"github.com/adrg/xdg"
"github.com/spf13/cobra"
+ "source.monogon.dev/go/logging"
"source.monogon.dev/metropolis/cli/metroctl/core"
)
@@ -61,14 +62,6 @@
rootCmd.PersistentFlags().BoolVar(&flags.acceptAnyCA, "insecure-accept-and-persist-first-encountered-ca", false, "Accept the first encountered CA while connecting as the trusted CA for future metroctl connections with this config path. This is very insecure and should only be used for testing.")
}
-// rpcLogger passes through the cluster resolver logs, if "--verbose" flag was
-// used.
-func rpcLogger(f string, args ...interface{}) {
- if flags.verbose {
- log.Printf("resolver: "+f, args...)
- }
-}
-
func main() {
cobra.CheckErr(rootCmd.Execute())
}
@@ -86,11 +79,15 @@
if flags.acceptAnyCA {
tofu = &acceptall{}
}
+ logger := logging.NewWriterBackend(os.Stderr)
+ if !flags.verbose {
+ logger.MinimumSeverity = logging.WARNING
+ }
return &core.ConnectOptions{
ConfigPath: flags.configPath,
ProxyServer: flags.proxyAddr,
Endpoints: flags.clusterEndpoints,
- ResolverLogger: rpcLogger,
+ ResolverLogger: logger,
TOFU: tofu,
}
}