From dbe0b8ef41092c8c61819dcf99e59af7e8d3b823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Buko=C5=A1ek?= Date: Mon, 22 Jan 2024 14:19:43 +0100 Subject: [PATCH] go/oasis-net-runner: Add ability to set node log level and format --- go/oasis-net-runner/cmd/root.go | 4 ++++ go/oasis-test-runner/oasis/network.go | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/go/oasis-net-runner/cmd/root.go b/go/oasis-net-runner/cmd/root.go index 5dbe6589182..68f2737226e 100644 --- a/go/oasis-net-runner/cmd/root.go +++ b/go/oasis-net-runner/cmd/root.go @@ -139,6 +139,10 @@ func runRoot(cmd *cobra.Command, _ []string) error { return fmt.Errorf("root: failed to instantiate fixture: %w", err) } + // Set logging level and format for all spawned nodes. + net.Config().NodeLogLevel = viper.GetString(cfgLogLevel) + net.Config().NodeLogFormat = viper.GetString(cfgLogFmt) + // Start the network and keep it running. if err = net.Start(); err != nil { logger.Error("failed to start network", diff --git a/go/oasis-test-runner/oasis/network.go b/go/oasis-test-runner/oasis/network.go index b91e416f67e..3792146416e 100644 --- a/go/oasis-test-runner/oasis/network.go +++ b/go/oasis-test-runner/oasis/network.go @@ -162,6 +162,12 @@ type NetworkCfg struct { // nolint: maligned // externally-provided. UseShortGrpcSocketPaths bool `json:"-"` + // NodeLogLevel is the log level to use for created nodes. + NodeLogLevel string `json:"node_log_level,omitempty"` + + // NodeLogFormat is the log format to use for created nodes. + NodeLogFormat string `json:"node_log_format,omitempty"` + // Nodes lists the names of nodes to be created, enabling an N:M mapping between physical node // processes and the features they host. If a feature is specified as attached to a node that // isn't listed here, a new node will be created automatically, so this list can normally be @@ -638,8 +644,16 @@ func (net *Network) startOasisNode( cfg.Common.DataDir = node.DataDir() cfg.Common.Log.Level = make(map[string]string) - cfg.Common.Log.Level["default"] = "debug" - cfg.Common.Log.Format = "json" + if net.Config().NodeLogLevel != "" { + cfg.Common.Log.Level["default"] = net.Config().NodeLogLevel + } else { + cfg.Common.Log.Level["default"] = "debug" + } + if net.Config().NodeLogFormat != "" { + cfg.Common.Log.Format = net.Config().NodeLogFormat + } else { + cfg.Common.Log.Format = "json" + } cfg.Common.Log.File = nodeLogPath(node.dir) cfg.Genesis.File = net.GenesisPath() @@ -710,6 +724,8 @@ func (net *Network) startOasisNode( net.logger.Info("launching Oasis node", "args", strings.Join(args, " "), + "log_level", cfg.Common.Log.Level["default"], + "log_format", cfg.Common.Log.Format, ) if err = cmd.Start(); err != nil {