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

libcontainer logging #3434

Open
kolyshkin opened this issue Mar 27, 2022 · 7 comments
Open

libcontainer logging #3434

kolyshkin opened this issue Mar 27, 2022 · 7 comments

Comments

@kolyshkin
Copy link
Contributor

As pointed out by @mrunalp in #3433 (comment), libcontainer packages should not do any logging, since this is a library used by other users.

Unfortunately, libcontainer is also a part of runc which is a CLI tool and we expect it to do some logging.

This can be solved by having a logger in libcontainer, which defaults to a shallow implementation that does nothing, and then runc can redefine it to use logrus. Something like libcontainer.SetLogger() perhaps (where the argument is logrus compatible logger).

WDYT @opencontainers/runc-maintainers?

@kolyshkin
Copy link
Contributor Author

One other thing somewhat releated to this issue is getting rid of logrus entirely, since it is no longer maintained. I am not sure though if there's a better alternative that supports at least JSON output. Maybe @thaJeztah has some ideas?

@kolyshkin
Copy link
Contributor Author

Alternatively, libcontainer can have a build tag to disable any logging -- by creating a shallow logrus implementation. Not sure if that's a good idea, just thinking out loud here.

@thaJeztah
Copy link
Member

Yeh, there may be alternatives to logrus, OTOH, it's still widely used (and I think I was given write access to that repository in case urgent things are needed).

One option could be to use a "context logger", similar to how containerd approaches this; in this case the logger can be attached to the context, so we can still pass it (but others may skip that); https://github.com/containerd/containerd/blob/main/log/context.go

Overall, I agree that for library code, logging should be optional (at least). In this specific case (sync.Once()), it's a tricky one; we can store the error, but that means it will always be returned (of course caller can decide what to do)

@danishprakash
Copy link
Contributor

We recently spent some time finding a logger and ended up choosing https://github.com/uber-go/zap for a custom logger wrapper we're currently writing at work. But as @thaJeztah said, it's still widely used and we still use it for a lot of our services.

@thaJeztah do you mean using context.Values for storing a logger instance and propagating that around? I think that's generally not deemed to be idiomatic[1] just because you're abstracting the logger instance which ideally should be an explicit argument to functions. Though I believe you are referencing containerd here wherein they are facilitating this through another package But it still doesn't feel idiomatic enough.

[1] - https://dave.cheney.net/2017/01/26/context-is-for-cancelation

@kolyshkin
Copy link
Contributor Author

The issue in question is make libcontainer logging optional. In other words, if runc is using libcontainer, log all the way. If someone else is using libcontainer, do not log (by default).

@kamizjw
Copy link

kamizjw commented Sep 6, 2022

I found that some log printing for libcontainer has been added in https://gitee.com/src-openeuler/runc, you can refer to its related implementation

@thaJeztah
Copy link
Member

There's also https://github.com/go-logr/logr, which tries to separate interface from implementation

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

No branches or pull requests

4 participants