Address comments in PR 1861

Refactor configuring logging into a reusable component
so that it can be nicely used in both main() and init process init()

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Co-authored-by: Giuseppe Capizzi <gcapizzi@pivotal.io>
Co-authored-by: Claudia Beresford <cberesford@pivotal.io>
Signed-off-by: Danail Branekov <danailster@gmail.com>
This commit is contained in:
Danail Branekov
2019-04-04 14:57:28 +03:00
parent feebfac358
commit c486e3c406
11 changed files with 381 additions and 134 deletions
+10 -13
View File
@@ -1,14 +1,14 @@
package main
import (
"os"
"runtime"
"strconv"
"fmt"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/logs"
_ "github.com/opencontainers/runc/libcontainer/nsenter"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"os"
"runtime"
)
func init() {
@@ -16,17 +16,14 @@ func init() {
runtime.GOMAXPROCS(1)
runtime.LockOSThread()
// in child process, we need to retrieve the log pipe
envLogPipe := os.Getenv("_LIBCONTAINER_LOGPIPE")
logPipeFd, err := strconv.Atoi(envLogPipe)
err := logs.ConfigureLogging(&logs.LoggingConfiguration{
LogPipeFd: os.Getenv("_LIBCONTAINER_LOGPIPE"),
LogFormat: "json",
IsDebug: true,
})
if err != nil {
return
panic(fmt.Sprintf("libcontainer: failed to configure logging: %v", err))
}
logPipe := os.NewFile(uintptr(logPipeFd), "logpipe")
logrus.SetOutput(logPipe)
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetLevel(logrus.DebugLevel)
logrus.Debug("child process in init()")
}
}