LogPrintln.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package logs
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/logs"
  5. orm2 "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // var Test = true
  9. var logx *logs.BeeLogger
  10. var logxE *logs.BeeLogger
  11. var logxData *logs.BeeLogger
  12. //var DeviceRealLogMap map[string]DeviceRealLogR // 设备实时日志
  13. type DeviceRealLogR struct {
  14. Time time.Time //
  15. Data []string // 泛型数组
  16. }
  17. func init() {
  18. //
  19. //DeviceRealLogMap = make(map[string]DeviceRealLogR)
  20. //go func() {
  21. // for true {
  22. // for key, value := range DeviceRealLogMap {
  23. // subM := time.Now().Sub(value.Time)
  24. // println(key+"日志-", subM.Minutes(), "分钟")
  25. // if subM.Minutes() > 3 {
  26. // delete(DeviceRealLogMap, key) // 删除日志
  27. // }
  28. // }
  29. //
  30. // time.Sleep(time.Minute * 1)
  31. // }
  32. //
  33. //}()
  34. logx = logs.NewLogger()
  35. logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log","perm":"0666"}`)
  36. logxE = logs.NewLogger()
  37. logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log","perm":"0666"}`)
  38. logxData = logs.NewLogger()
  39. logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log","perm":"0666"}`)
  40. orm2.DebugLog = orm2.NewLog(logx)
  41. // 测试 日志分割
  42. //go func() {
  43. // t := 1
  44. // orm2.DebugLog.Println("==========DebugLog=========")
  45. // for true {
  46. // t +=1
  47. // orm2.DebugLog.Println("DebugLog:",t)
  48. // time.Sleep(time.Second * 1)
  49. // }
  50. //}()
  51. //go TimeTask.OrmLog_MonitorScanStatus()
  52. }
  53. func Println(format string, v ...interface{}) {
  54. fmt.Println(format, v)
  55. logx.Info(format, v)
  56. }
  57. func PrintlnError(format string, v ...interface{}) {
  58. logxE.Error(format, v)
  59. logx.Info(format, v)
  60. }
  61. func PrintlnData(str string) {
  62. logxData.Info(str)
  63. }
  64. //func Println(a ...interface{}) {
  65. // if test {
  66. // fmt.Printf("=>", a)
  67. // }
  68. // logx.Info(">", a)
  69. //}
  70. // 日志
  71. // logs.Println(time.Now().Format("2006-01-02 15:04:05"), "=>", a)
  72. // 重要
  73. // logs.Println("MqttServer", " 存在报警 跳过:", string(msg))
  74. // 严重
  75. // logs.Println("MqttServer", " 存在报警 跳过:", string(msg))