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

cmd/contour: Add support for json log formatter #4486

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/4486-tsaarni-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Contour to produce logs in JSON format by specifying `--log-format=json` command line switch.
14 changes: 13 additions & 1 deletion cmd/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func main() {
app := kingpin.New("contour", "Contour Kubernetes ingress controller.")
app.HelpFlag.Short('h')

// 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")

envoyCmd := app.Command("envoy", "Sub-command for envoy actions.")
sdm, shutdownManagerCtx := registerShutdownManager(envoyCmd, log)

Expand Down Expand Up @@ -67,7 +70,16 @@ func main() {
gatewayProvisioner, gatewayProvisionerConfig := registerGatewayProvisioner(app)

args := os.Args[1:]
switch kingpin.MustParse(app.Parse(args)) {
cmd := kingpin.MustParse(app.Parse(args))

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

switch cmd {
case gatewayProvisioner.FullCommand():
runGatewayProvisioner(gatewayProvisionerConfig)
case sdm.FullCommand():
Expand Down
2 changes: 2 additions & 0 deletions site/content/docs/main/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Many of these flags are mirrored in the [Contour Configuration File](#configurat
| `--leader-election-resource-namespace` | The namespace of the resource (Lease) leader election will lease. |
| `-d, --debug` | Enable debug logging |
| `--kubernetes-debug=<log level>` | Enable Kubernetes client debug logging |
| `--log-format=<text|json>` | Log output format for Contour. Either text (default) or json. |

## Configuration File

Expand Down Expand Up @@ -446,6 +447,7 @@ connects to Contour:
| <nobr>--namespace</nobr> | projectcontour | Namespace the Envoy container will run, also configured via ENV variable "CONTOUR_NAMESPACE". Namespace is used as part of the metric names on static resources defined in the bootstrap configuration file. |
| <nobr>--xds-resource-version</nobr> | v3 | Currently, the only valid xDS API resource version is `v3`. |
| <nobr>--dns-lookup-family</nobr> | auto | Defines what DNS Resolution Policy to use for Envoy -> Contour cluster name lookup. Either v4, v6 or auto. |
| <nobr>--log-format | text | Log output format for Contour. Either text or json. |


[1]: {{< param github_url>}}/tree/{{< param version >}}/examples/contour/01-contour-config.yaml
Expand Down