Skip to content

Commit 27f8ee4

Browse files
committed
CORS-3436: capi: save log output to file
The same way we save installer log output to `$workdir/.openshift_install.log`, this change proposes saving the CAPI output to that file. Controller's output is displayed in stdout when log level is at least DEBUG.
1 parent bc9836a commit 27f8ee4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/clusterapi/system.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"io"
78
"net/url"
89
"os"
910
"path/filepath"
@@ -71,6 +72,8 @@ type system struct {
7172
wg sync.WaitGroup
7273
teardownOnce sync.Once
7374
cancel context.CancelFunc
75+
76+
logWriter *io.PipeWriter
7477
}
7578

7679
// Run launches the cluster-api system.
@@ -259,6 +262,9 @@ func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallCo
259262
return fmt.Errorf("unsupported platform %q", platform)
260263
}
261264

265+
// We only show controller logs if the log level is DEBUG or above
266+
c.logWriter = logrus.StandardLogger().WriterLevel(logrus.DebugLevel)
267+
262268
// Run the controllers.
263269
for _, ct := range controllers {
264270
if err := c.runController(ctx, ct); err != nil {
@@ -328,6 +334,8 @@ func (c *system) Teardown() {
328334
case <-time.After(60 * time.Second):
329335
logrus.Warn("Timed out waiting for local Cluster API system to shut down")
330336
}
337+
338+
c.logWriter.Close()
331339
})
332340
}
333341

@@ -492,7 +500,7 @@ func (c *system) runController(ctx context.Context, ct *controller) error {
492500

493501
// Run the controller and store its state.
494502
logrus.Infof("Running process: %s with args %v", ct.Name, ct.Args)
495-
if err := pr.Start(ctx, os.Stdout, os.Stderr); err != nil {
503+
if err := pr.Start(ctx, c.logWriter, c.logWriter); err != nil {
496504
return fmt.Errorf("failed to start controller %q: %w", ct.Name, err)
497505
}
498506
ct.state = pr

0 commit comments

Comments
 (0)