diff --git a/example/os/log/rotate/config.toml b/example/os/log/rotate/config.toml new file mode 100644 index 000000000..623e47935 --- /dev/null +++ b/example/os/log/rotate/config.toml @@ -0,0 +1,8 @@ +[logger] +path = "./log" +file = "{Y-m-d-H-i}.log" +level = "all" +stdout = true +rotateExpire = "1m" +rotateBackupLimit = 4 +rotateCheckInterval = "5s" diff --git a/example/os/log/rotate/main.go b/example/os/log/rotate/main.go new file mode 100644 index 000000000..5a3fcbf2f --- /dev/null +++ b/example/os/log/rotate/main.go @@ -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) + } +}