LogPrintln.go 1.9 KB

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