package logs

import (
	"fmt"
	"github.com/astaxie/beego/logs"
	orm2 "github.com/beego/beego/v2/client/orm"
	"runtime"
)

var Test = true
var logx *logs.BeeLogger
var logxE *logs.BeeLogger
var logxData *logs.BeeLogger
var logxOrm *logs.BeeLogger

func init() {

	if runtime.GOOS == "windows" {
		Test = true
	} else {
		Test = false
	}

	logx = logs.NewLogger()
	err := logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log"}`)
	if err != nil {
		fmt.Println("logs/logx/logx.log 初始化失败！")
	}

	logxE = logs.NewLogger()
	err = logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log"}`)
	if err != nil {
		fmt.Println("logs/logx/logx.log 初始化失败！")
	}
	logxData = logs.NewLogger()
	err = logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log"}`)
	if err != nil {
		fmt.Println("logs/logx/logx.log 初始化失败！")
	}
	logxOrm = logs.NewLogger()
	err = logxOrm.SetLogger(logs.AdapterFile, `{"filename":"logs/Orm/logx.log"}`)
	if err != nil {
		fmt.Println("logs/logx/logx.log 初始化失败！")
	}

	if !Test {
		orm2.DebugLog = orm2.NewLog(logxOrm)
	}
	//

	// 测试 日志分割
	//go func() {
	//	t := 1
	//	orm2.DebugLog.Println("==========DebugLog=========")
	//	for true {
	//		t +=1
	//		orm2.DebugLog.Println("DebugLog:",t)
	//		time.Sleep(time.Second * 1)
	//	}
	//}()
	//go TimeTask.OrmLog_MonitorScanStatus()
}

func Println(format string, v ...interface{}) {
	if Test {
		fmt.Println(format, v)
	}
	logx.Info(format, v)

}

func PrintlnError(format string, v ...interface{}) {
	if Test {
		fmt.Println(format, v)
	}
	logxE.Error(format, v)
	logx.Info(format, v)
}

func PrintlnData(str string) {
	if Test {
		fmt.Println(str)
	}
	logxData.Info(str)
}

//func Println(a ...interface{}) {
//	if test {
//		fmt.Printf("=>", a)
//	}
//	logx.Info(">", a)
//}

// 日志
// logs.Println(time.Now().Format("2006-01-02 15:04:05"), "=>", a)

// 重要
// logs.Println("MqttServer", " 存在报警 跳过:", string(msg))

// 严重
// logs.Println("MqttServer", " 存在报警 跳过:", string(msg))
