Skip to content

Commit dd28309

Browse files
Merge pull request #8218 from r4f4/capi-log-to-file
CORS-3436: capi: save log output to file
2 parents 514c886 + 27f8ee4 commit dd28309

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"
@@ -72,6 +73,8 @@ type system struct {
7273
wg sync.WaitGroup
7374
teardownOnce sync.Once
7475
cancel context.CancelFunc
76+
77+
logWriter *io.PipeWriter
7578
}
7679

7780
// Run launches the cluster-api system.
@@ -272,6 +275,9 @@ func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallCo
272275
return fmt.Errorf("unsupported platform %q", platform)
273276
}
274277

278+
// We only show controller logs if the log level is DEBUG or above
279+
c.logWriter = logrus.StandardLogger().WriterLevel(logrus.DebugLevel)
280+
275281
// Run the controllers.
276282
for _, ct := range controllers {
277283
if err := c.runController(ctx, ct); err != nil {
@@ -341,6 +347,8 @@ func (c *system) Teardown() {
341347
case <-time.After(60 * time.Second):
342348
logrus.Warn("Timed out waiting for local Cluster API system to shut down")
343349
}
350+
351+
c.logWriter.Close()
344352
})
345353
}
346354

@@ -505,7 +513,7 @@ func (c *system) runController(ctx context.Context, ct *controller) error {
505513

506514
// Run the controller and store its state.
507515
logrus.Infof("Running process: %s with args %v", ct.Name, ct.Args)
508-
if err := pr.Start(ctx, os.Stdout, os.Stderr); err != nil {
516+
if err := pr.Start(ctx, c.logWriter, c.logWriter); err != nil {
509517
return fmt.Errorf("failed to start controller %q: %w", ct.Name, err)
510518
}
511519
ct.state = pr

0 commit comments

Comments
 (0)