Skip to content

Allow configuration of different log formats: text, json#4803

Merged
estesp merged 1 commit intocontainerd:masterfrom
ungureanuvladvictor:vladu/json-logging
Dec 7, 2020
Merged

Allow configuration of different log formats: text, json#4803
estesp merged 1 commit intocontainerd:masterfrom
ungureanuvladvictor:vladu/json-logging

Conversation

@ungureanuvladvictor
Copy link
Copy Markdown
Contributor

@ungureanuvladvictor ungureanuvladvictor commented Dec 3, 2020

This PR allows configuring logrus to output in 2 different formats:

  • text (default which is today)
  • json (new addition)

The way I've configured this is to be via the debug section in the toml config. I did not add a CLI flag for this, curious if you folks think this would be useful here. In my experience I've found all my interactions with containerd via the toml config.

@k8s-ci-robot
Copy link
Copy Markdown

Hi @ungureanuvladvictor. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ungureanuvladvictor ungureanuvladvictor marked this pull request as ready for review December 3, 2020 19:20
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 3, 2020

Build succeeded.

Comment thread cmd/containerd/command/main.go Outdated
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 3, 2020

Build succeeded.

Comment thread services/server/config/config.go Outdated
Comment thread cmd/containerd/command/main.go Outdated
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 4, 2020

Build succeeded.

@AkihiroSuda
Copy link
Copy Markdown
Member

LGTM, but please consider squashing commits

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 4, 2020

Build succeeded.

@fuweid
Copy link
Copy Markdown
Member

fuweid commented Dec 4, 2020

# https://github.com/containerd/containerd/blob/master/cmd/containerd/command/main.go#L54
func init() {
	logrus.SetFormatter(&logrus.TextFormatter{
		TimestampFormat: log.RFC3339NanoFixed,
		FullTimestamp:   true,
	})

Could we remove this part?

@ungureanuvladvictor
Copy link
Copy Markdown
Contributor Author

@fuweid -- addressed your comment!

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 4, 2020

Build succeeded.

Copy link
Copy Markdown
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@estesp estesp merged commit 9f97514 into containerd:master Dec 7, 2020
@ungureanuvladvictor ungureanuvladvictor deleted the vladu/json-logging branch December 7, 2020 16:35
@weekyuan
Copy link
Copy Markdown

weekyuan commented Dec 9, 2020

I recompiled and replaced the containerd of the node, and then restarted the containerd service. However, the container log is still in text format and has not been changed to json format.

I adjusted this part of the configuration:
[debug] address = "" uid = 0 gid = 0 level = "" format = "json"

@ungureanuvladvictor
Copy link
Copy Markdown
Contributor Author

@weekyuan -- I gave your config a test with 318e34b and I see the logs in JSON format. My debug block is in this format:

[debug]
  address = ""
  uid = 0
  gid = 0
  level = ""
  format = "json"

@bekirby
Copy link
Copy Markdown

bekirby commented Oct 6, 2021

Hi @ungureanuvladvictor, I am new to using containerd and am also trying to change the logging output to JSON. I am using containerd v1.5.6 and edited the debug block as you suggested and I am not seeing JSON output in /var/log/containers/<container.log>.

Am i misunderstanding what this enhancement does? I also have not been able to find any documentation on this new setting. Any help would be appreciated.

Thanks!

@ungureanuvladvictor
Copy link
Copy Markdown
Contributor Author

@bekirby -- this feature is for the logs of containerd itself and not the log format of the containers that are running.

@bekirby
Copy link
Copy Markdown

bekirby commented Oct 9, 2021

@ungureanuvladvictor just happened to be on and saw your reply - thank you. Is it possible to change the log format of the containers do you know? We are switching from Docker to containerd and that is one of the problems we are facing.

@ungureanuvladvictor
Copy link
Copy Markdown
Contributor Author

As far as I know this is not possible right now but I'd suggest asking this on the #containerd slack chan -- maybe more folks know this.

Some relevant issues + links:

@bekirby
Copy link
Copy Markdown

bekirby commented Oct 9, 2021

Thank you very much for the info!

@mikebrow
Copy link
Copy Markdown
Member

I think to do plug-able logging format for kubelet CRI containers we would need a KEP see github.com/kubernetes/enhancements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants