-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Logging improvements #3157
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
Logging improvements #3157
Changes from all commits
f77fb7a
8d8415e
c482690
c3910e7
b55b308
a20c8b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "runtime" | ||
| "strconv" | ||
|
|
||
| "github.com/opencontainers/runc/libcontainer" | ||
| "github.com/opencontainers/runc/libcontainer/logs" | ||
| _ "github.com/opencontainers/runc/libcontainer/nsenter" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
@@ -19,25 +17,19 @@ func init() { | |
| runtime.GOMAXPROCS(1) | ||
| runtime.LockOSThread() | ||
|
|
||
| level := os.Getenv("_LIBCONTAINER_LOGLEVEL") | ||
| logLevel, err := logrus.ParseLevel(level) | ||
| logLevel, err := logrus.ParseLevel(os.Getenv("_LIBCONTAINER_LOGLEVEL")) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("libcontainer: failed to parse log level: %q: %v", level, err)) | ||
| panic(err) | ||
| } | ||
|
|
||
| logPipeFdStr := os.Getenv("_LIBCONTAINER_LOGPIPE") | ||
| logPipeFd, err := strconv.Atoi(logPipeFdStr) | ||
| logPipeFd, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGPIPE")) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("libcontainer: failed to convert environment variable _LIBCONTAINER_LOGPIPE=%s to int: %s", logPipeFdStr, err)) | ||
| } | ||
| err = logs.ConfigureLogging(logs.Config{ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the original intent was to try to abstract away logrus, to allow swapping with something else, but given that we already import logrus here, I agree that it doesn't add anything really useful.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It actually makes things worse because
|
||
| LogPipeFd: logPipeFd, | ||
| LogFormat: "json", | ||
| LogLevel: logLevel, | ||
| }) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("libcontainer: failed to configure logging: %v", err)) | ||
| panic(err) | ||
| } | ||
|
|
||
| logrus.SetLevel(logLevel) | ||
| logrus.SetOutput(os.NewFile(uintptr(logPipeFd), "logpipe")) | ||
| logrus.SetFormatter(new(logrus.JSONFormatter)) | ||
| logrus.Debug("child process in init()") | ||
|
|
||
| factory, _ := libcontainer.New("") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message from
logrus.ParseLevelis descriptive enough, no need to wrap it.