Skip to content

Commit

Permalink
Merge pull request #13095 from hexfusion/cp-13049
Browse files Browse the repository at this point in the history
[release-3.5]: [Fix] --log-outputs relative path are not supported when --log-rotate-config-json is defined
  • Loading branch information
hexfusion authored Jun 9, 2021
2 parents b327edf + 98bbc01 commit 5d52fae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/embed/config_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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")
}
})
}
}

0 comments on commit 5d52fae

Please sign in to comment.