package util

import (
	rotatelogs "github.com/lestrrat/go-file-rotatelogs"
	"github.com/sirupsen/logrus"
	"os"
	"path"
	"time"
)

var _ = func() error {
	err := os.MkdirAll("./log", os.ModeDir)
	if err != nil {
		logrus.Error("创建日志目录失败!", err)
		return 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)
	return nil
}()
