123456789101112131415161718192021222324252627 |
- package initialize
- import (
- rotatelogs "github.com/lestrrat/go-file-rotatelogs"
- "github.com/sirupsen/logrus"
- "os"
- "path"
- "time"
- )
- func InitLogrus() {
- err := os.MkdirAll("./log", os.ModeDir)
- if err != nil {
- panic(err)
- }
- fileName := path.Join("./log", "info")
- writer, _ := rotatelogs.New(
- fileName+".%Y%m%d.log",
- rotatelogs.WithMaxAge(15*24*time.Hour), // 文件最大保存时间
- rotatelogs.WithRotationTime(24*time.Hour), // 日志切割时间间隔
- )
- logrus.SetFormatter(&logrus.JSONFormatter{})
- logrus.SetLevel(logrus.DebugLevel)
- logrus.SetOutput(os.Stdout)
- logrus.SetReportCaller(true)
- logrus.SetOutput(writer)
- }
|