Skip to content

Commit

Permalink
go/oasis-net-runner: Add ability to set node log level and format
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Jan 30, 2024
1 parent 841b229 commit 77f9efd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changelog/5534.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/oasis-net-runner: Add ability to set node log level and format

Previously, every node started by the net runner had the default
log level of debug, while now it's possible to set it to other
levels. The log format can also be changed.
4 changes: 4 additions & 0 deletions go/oasis-net-runner/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 18 additions & 2 deletions go/oasis-test-runner/oasis/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,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
Expand Down Expand Up @@ -630,8 +636,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()

Expand Down Expand Up @@ -702,6 +716,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 {
Expand Down

0 comments on commit 77f9efd

Please sign in to comment.