Skip to content

Commit 90026df

Browse files
committed
added deprecate message with support for 'log.rotate.mode'
1 parent 05b905f commit 90026df

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

file_receiver.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"aahframework.org/essentials.v0"
1818
)
1919

20+
const defaultRotatePolicy = "daily"
21+
2022
var (
2123
// backupTimeFormat is used for timestamp with filename on rotation
2224
backupTimeFormat = "2006-01-02-15-04-05.000"
@@ -58,9 +60,20 @@ func (f *FileReceiver) Init(cfg *config.Config) error {
5860
return fmt.Errorf("log: unsupported format '%s'", f.formatter)
5961
}
6062

61-
f.rotatePolicy = cfg.StringDefault("log.rotate.policy", "daily")
63+
if policy, found := cfg.String("log.rotate.mode"); found {
64+
f.rotatePolicy = policy
65+
if ess.IsStrEmpty(f.rotatePolicy) {
66+
f.rotatePolicy = defaultRotatePolicy
67+
}
68+
69+
// DEPRECATED, to be removed in v1.0
70+
Warnf("DEPRECATED: Config 'log.rotate.mode' is deprecated in v0.7, use 'log.rotate.policy = \"%s\"' instead. Deprecated config will not break your functionality, its good to update to latest config.", f.rotatePolicy)
71+
} else {
72+
f.rotatePolicy = cfg.StringDefault("log.rotate.policy", defaultRotatePolicy)
73+
}
74+
6275
switch f.rotatePolicy {
63-
case "daily":
76+
case defaultRotatePolicy:
6477
f.openDay = f.getDay()
6578
case "lines":
6679
f.maxLines = int64(cfg.IntDefault("log.rotate.lines", 0))

file_receiver_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ func TestFileLoggerRotation(t *testing.T) {
5959
testFileLogger(t, fileConfigStr3, 5000)
6060
cleaupFiles("*.log")
6161

62+
fileConfigStr4 := `
63+
log {
64+
receiver = "file"
65+
level = "debug"
66+
file = "daily-aah-filename.log"
67+
rotate {
68+
mode = ""
69+
}
70+
}
71+
`
72+
73+
testFileLogger(t, fileConfigStr4, 50)
74+
cleaupFiles("*.log")
75+
6276
// JSON
6377
fileConfigStrJSON := `
6478
log {

0 commit comments

Comments
 (0)