LogPrintln.go 2.3 KB

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