1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package logs
- import (
- "fmt"
- "github.com/astaxie/beego/logs"
- orm2 "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // var Test = true
- var logx *logs.BeeLogger
- var logxE *logs.BeeLogger
- var logxData *logs.BeeLogger
- //var DeviceRealLogMap map[string]DeviceRealLogR // 设备实时日志
- type DeviceRealLogR struct {
- Time time.Time //
- Data []string // 泛型数组
- }
- func init() {
- //
- //DeviceRealLogMap = make(map[string]DeviceRealLogR)
- //go func() {
- // for true {
- // for key, value := range DeviceRealLogMap {
- // subM := time.Now().Sub(value.Time)
- // println(key+"日志-", subM.Minutes(), "分钟")
- // if subM.Minutes() > 3 {
- // delete(DeviceRealLogMap, key) // 删除日志
- // }
- // }
- //
- // time.Sleep(time.Minute * 1)
- // }
- //
- //}()
- logx = logs.NewLogger()
- logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log","perm":"0666"}`)
- logxE = logs.NewLogger()
- logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log","perm":"0666"}`)
- logxData = logs.NewLogger()
- logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log","perm":"0666"}`)
- orm2.DebugLog = orm2.NewLog(logx)
- // 测试 日志分割
- //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{}) {
- fmt.Println(format, v)
- logx.Info(format, v)
- }
- func PrintlnError(format string, v ...interface{}) {
- logxE.Error(format, v)
- logx.Info(format, v)
- }
- func PrintlnData(str string) {
- 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))
|