runc/patch/0015-runc-fix-runc-log-decode-failed.patch
2023-01-05 17:23:54 +08:00

63 lines
1.4 KiB
Diff

From 5584140c9549c2c9c6a0b0c5afea0850d1e88926 Mon Sep 17 00:00:00 2001
From: zhongjiawei <zhongjiawei1@huawei.com>
Date: Thu, 5 Jan 2023 16:32:43 +0800
Subject: [PATCH] runc: fix runc log decode failed
---
main.go | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/main.go b/main.go
index 0a6f3b4..6e9101a 100644
--- a/main.go
+++ b/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