From c940ccbc26322c4dae9b3c7caa82d5e2eefcf7b1 Mon Sep 17 00:00:00 2001 From: zhong-jiawei-1 Date: Fri, 21 Oct 2022 16:40:34 +0800 Subject: [PATCH] runc: fix runc log decode failed --- runc-1.1.3/main.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/runc-1.1.3/main.go b/runc-1.1.3/main.go index 0a6f3b4..6e9101a 100644 --- a/runc-1.1.3/main.go +++ b/runc-1.1.3/main.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "errors" "fmt" "io" @@ -10,6 +11,7 @@ import ( "runtime" "strconv" "strings" + "time" "github.com/opencontainers/runc/libcontainer/seccomp" "github.com/opencontainers/runtime-spec/specs-go" @@ -219,7 +221,7 @@ func configLogrus(context *cli.Context) error { logrus.SetOutput(f) hook, serr := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO|syslog.LOG_USER, "docker-runc") if serr != nil { - fmt.Fprint(f, fmt.Sprintf("Leo: new syslog hook get %s", serr)) + logToFile(f, "error", fmt.Sprintf("Leo: new syslog hook get %s", serr)) } else { logrus.AddHook(hook) } @@ -238,3 +240,20 @@ func configLogrus(context *cli.Context) error { } return nil } + +func logToFile(f io.Writer, level string, msg string) { + var ( + log struct { + Level string + Msg string + Time time.Time + } + ) + log.Level = level + log.Msg = msg + log.Time = time.Now() + s, err := json.Marshal(log) + if err != nil { + fmt.Fprint(f, string(s)) + } +} -- 2.30.0