From fed3bc3084e33c3ba512f27f0a7855ba3da64473 Mon Sep 17 00:00:00 2001 From: Mr-Mu <530148599@qq.com> Date: Thu, 27 May 2021 16:44:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Fix]=E6=BB=9A=E5=8A=A8=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=A7=A3=E6=9E=90=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 例如 rotate:test.log 路径解析不正确 --- server/embed/config_logging.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/embed/config_logging.go b/server/embed/config_logging.go index 645985f0f1d..9cb6e577765 100644 --- a/server/embed/config_logging.go +++ b/server/embed/config_logging.go @@ -87,7 +87,11 @@ func (cfg *Config) setupLogging() error { var path string if cfg.EnableLogRotation { // append rotate scheme to logs managed by lumberjack log rotation - path = fmt.Sprintf("rotate:%s", v) + if v[0:1] == "/" { + path = fmt.Sprintf("rotate:/%%2F%s", v[1:]) + } else { + path = fmt.Sprintf("rotate:/%s", v) + } } else { path = v } @@ -254,7 +258,7 @@ func setupLogRotation(logOutputs []string, logRotateConfigJSON string) error { } } zap.RegisterSink("rotate", func(u *url.URL) (zap.Sink, error) { - logRotationConfig.Filename = u.Path + logRotationConfig.Filename = u.Path[1:] return &logRotationConfig, nil }) return nil From 98bbc0107f27a53686984d5e6e40a21778b88d19 Mon Sep 17 00:00:00 2001 From: Mr-Mu <530148599@qq.com> Date: Thu, 27 May 2021 22:49:41 +0800 Subject: [PATCH 2/2] TestLogRotation add log output relative path TestLogRotation add test log output relative path test --- server/embed/config_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/embed/config_test.go b/server/embed/config_test.go index b86d0d6c246..d0ff013f8cf 100644 --- a/server/embed/config_test.go +++ b/server/embed/config_test.go @@ -304,6 +304,11 @@ func TestLogRotation(t *testing.T) { logOutputs: []string{"stderr", "/tmp/path"}, logRotationConfig: `{"maxsize": 1}`, }, + { + name: "log output relative path", + logOutputs: []string{"stderr", "tmp/path"}, + logRotationConfig: `{"maxsize": 1}`, + }, { name: "no file targets", logOutputs: []string{"stderr"}, @@ -361,6 +366,9 @@ func TestLogRotation(t *testing.T) { if err == nil && tt.wantErr { t.Errorf("test %q, expected error, got nil", tt.name) } + if err == nil { + cfg.GetLogger().Info("test log") + } }) } }