example: log rotate (#3137)

This commit is contained in:
海亮
2023-11-08 21:23:39 +08:00
committed by GitHub
parent a17849bc39
commit 5f5b82188c
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,8 @@
[logger]
path = "./log"
file = "{Y-m-d-H-i}.log"
level = "all"
stdout = true
rotateExpire = "1m"
rotateBackupLimit = 4
rotateCheckInterval = "5s"

View File

@ -0,0 +1,23 @@
package main
import (
"context"
"time"
"github.com/gogf/gf/v2/frame/g"
)
func main() {
ctx := context.Background()
mylog := g.Log()
for {
mylog.Debug(ctx, "debug")
time.Sleep(time.Second)
mylog.Info(ctx, "info")
time.Sleep(time.Second)
mylog.Warning(ctx, "warning")
time.Sleep(time.Second)
mylog.Error(ctx, "error")
time.Sleep(time.Second)
}
}