Update dockerd to support JSON logging format#45737
Update dockerd to support JSON logging format#45737corhere merged 1 commit intomoby:masterfrom pkwarren:pkw/issue-44940-dockerd-json-logs
Conversation
corhere
left a comment
There was a problem hiding this comment.
Looks good! My only request is to use constants for "json" and "text" instead of spreading more string literals everywhere. I'm even tempted to reuse the log.TextFormat and log.JSONFormat constants from containerd to really emphasize that the log format options have to align with the options containerd supports so that supervised containerd can be successfully configured.
|
Bikeshedding: perhaps we should use |
cmd/dockerd/daemon.go
Outdated
| if logFormat := cli.Config.LogFormat; logFormat != "" && logFormat != "text" { | ||
| opts = append(opts, supervisor.WithLogFormat(logFormat)) | ||
| } | ||
|
|
There was a problem hiding this comment.
Without punching it through, I got inconsistent formatted log lines (some JSON, some text) when testing (since the dockerd logs also include the containerd logs).
If we're punching through to containerd we would either have to use the same names as containerd, or map |
corhere
left a comment
There was a problem hiding this comment.
LGTM! Please squash down to a single commit and force-push so it's ready to merge.
Yup, I understand the downside/inconvenience. My concern here is that that's what one would get in the "normal" situation where |
|
@thaJeztah - thank you for the context. As a new contributor this is helpful.
One thing that may not be clear from the changes - https://github.com/moby/moby/pull/45737/files#diff-4c6f83cd169941ac3f98bf9b46a442581492bad0318d756599e65d8a60bfed27R18-R23 is setting a variable which will be written out to the containerd config file (this doesn't result in passing a different command line option like |
When running a separate systemd units, dockerd logs will be segregated from the containerd logs in the journal so it would not be a big deal if the format (or verbosity) of logging was inconsistent between them. The only time it would be an issue for the log formats to diverge is when both daemons log to the same stream: when dockerd runs a managed containerd subprocess. Even if we were to remove propagation of the log level to the managed containerd config, I strongly believe that aligning the log format for all processes sharing the log stream should be included in the "bare minimum" set of of options managed by dockerd. |
|
This has two reviews and appears to be passing all CI checks. I'm happy to fix any follow up issues, but if it is ready to go what are the next steps to close this PR? |
|
We discussed this during the maintainer's call again; @thaJeztah has reservations about adding more to the managed-containerd path, but I think in this case it is justified (especially with the merge of #45799). @thaJeztah, are you still -1 on this one? Looks like this needs a rebase as well. |
Update docker to support a '--log-format' option, which accepts either 'text' (default) or 'json'. Propagate the log format to containerd as well, to ensure that everything will be logged consistently. Signed-off-by: Philip K. Warren <[email protected]>
Rebased and removed the containerdlog import alias. |
- What I did
Update docker to support a
--log-formatoption, which accepts eithertext(default) orjson. Propagate the log format to containerd as well, to ensure that everything will be logged consistently.Fixes #44940.
- How I did it
Added a new CLI flag
--log-formatwhich acceptstext(default) orjson. Propagate log format to containerd so that all daemon output uses consistent formatting.- How to verify it
Run dockerd with
--log-format=jsonand--log-format=text(or leaving the option unset) to verify both encoding formats. This should set consistent log formats for both dockerd and containerd.- Description for the changelog
Add a
--log-formatoption to dockerd to allow logging in text (default) or JSON format.- A picture of a cute animal (not mandatory but encouraged)