package TimeTask

import (
	"fmt"
	"github.com/robfig/cron/v3"
	"io/ioutil"
	"os"
	"time"
)

var OrmLogOrmLog *os.File
// ORM 日志清理
func OrmLog()  {
	crontab := cron.New(cron.WithSeconds())
	ss := "1 1 1 * * *"
	_, err := crontab.AddFunc(ss, OrmLog_MonitorScanStatus)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		fmt.Println("初始化成功")
	}
	crontab.Start()
	defer crontab.Stop()
	select {}
}
func OrmLog_MonitorScanStatus()  {

	fmt.Println("------- ORM 日志清理 --------")
	data, err := ioutil.ReadFile(OrmLogOrmLog.Name())
	if err != nil {
		fmt.Printf("文件打开失败=%v\n", err)
		return
	}
	err = ioutil.WriteFile("logs/orm/logx_"+time.Now().Format("2006-01-02") +".log", data, 0666)
	if err != nil {
		fmt.Printf("文件打开失败=%v\n", err)
	}
	fmt.Println("清空：",os.Truncate(OrmLogOrmLog.Name(), 0))

}
