123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package logs
- import (
- "fmt"
- "github.com/astaxie/beego/logs"
- "runtime"
- "time"
- )
- var Test = true
- var logx *logs.BeeLogger
- var logxE *logs.BeeLogger
- var logxMqtt *logs.BeeLogger
- var logxData *logs.BeeLogger
- var logxOrm *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)
- fmt.Println(key+"日志-", subM.Minutes(), "分钟")
- if subM.Minutes() > 3 {
- delete(DeviceRealLogMap, key) // 删除日志
- }
- }
- time.Sleep(time.Minute * 1)
- }
- }()
- if runtime.GOOS == "windows" {
- Test = true
- } else {
- Test = false
- }
- logx = logs.NewLogger()
- logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log"}`)
- logxE = logs.NewLogger()
- logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log"}`)
- logxMqtt = logs.NewLogger()
- logxMqtt.SetLogger(logs.AdapterFile, `{"filename":"logs/Mqtt/logx.log"}`)
- logxData = logs.NewLogger()
- logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log"}`)
- logxOrm = logs.NewLogger()
- logxOrm.SetLogger(logs.AdapterFile, `{"filename":"logs/Orm/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{}) {
- fmt.Println(format, v)
- logx.Info(format, v)
- }
- func PrintlnError(format string, v ...interface{}) {
- fmt.Println(format, v)
- logxE.Error(format, v)
- logx.Info(format, v)
- }
- func PrintlnMqtt(str string) {
- fmt.Println(str)
- logxMqtt.Info(str)
- }
- func PrintlnData(str string) {
- 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))
|