Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds log-path to the Contour cli #5813

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/unreleased/5813-davinci26-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Adds `log-path` to the Contour cli

This change allows users to write the output of `Contour` to a file instead of stdout.
10 changes: 9 additions & 1 deletion cmd/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

// Log-format applies to log format of all sub-commands.
logFormat := app.Flag("log-format", "Log output format for Contour. Either text or json.").Default("text").Enum("text", "json")

logPath := app.Flag("log-path", "Log output path. If not specified it defaults to stderr.").Default("").String()

Check warning on line 48 in cmd/contour/contour.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/contour.go#L48

Added line #L48 was not covered by tests
bootstrap, bootstrapCtx := registerBootstrap(app)

certgenApp, certgenConfig := registerCertGen(app)
Expand Down Expand Up @@ -83,6 +83,14 @@
args := os.Args[1:]
cmd := kingpin.MustParse(app.Parse(args))

if *logPath != "" {
f, err := os.OpenFile(*logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.WithError(err).Fatalf("failed to open log file %s", *logPath)
}
log.Out = f

Check warning on line 91 in cmd/contour/contour.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/contour.go#L86-L91

Added lines #L86 - L91 were not covered by tests
}

switch *logFormat {
case "text":
log.SetFormatter(&logrus.TextFormatter{})
Expand Down