123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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 logxWData *logs.BeeLogger
- var logxMqtt *logs.BeeLogger
- var logxData *logs.BeeLogger
- var LogxOrm *logs.BeeLogger
- func init() {
- if runtime.GOOS == "windows" {
- Test = true
- } else {
- Test = false
- }
- logx = logs.NewLogger()
- logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log","MaxDays":30}`)
- logxE = logs.NewLogger()
- logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log","MaxDays":180}`)
- logxMqtt = logs.NewLogger()
- logxMqtt.SetLogger(logs.AdapterFile, `{"filename":"logs/Mqtt/logx.log","MaxDays":30}`)
- logxData = logs.NewLogger()
- logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log","MaxDays":7}`)
- logxWData = logs.NewLogger()
- logxWData.SetLogger(logs.AdapterFile, `{"filename":"logs/logxWData/logx.log","MaxDays":300}`)
- LogxOrm = logs.NewLogger()
- LogxOrm.SetLogger(logs.AdapterFile, `{"filename":"logs/Orm/logx.log","MaxDays":7}`)
- 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 PrintlnMqtt(str string) {
- if Test {
- fmt.Println(str)
- }
- logxMqtt.Info(str)
- }
- func PrintlnWData(format string, v ...interface{}) {
- 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))
|