LogPrintln.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package logs
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/logs"
  5. orm2 "github.com/beego/beego/v2/client/orm"
  6. "runtime"
  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. func init() {
  15. if runtime.GOOS == "windows" {
  16. Test = true
  17. } else {
  18. Test = false
  19. }
  20. logx = logs.NewLogger()
  21. logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log"}`)
  22. logxE = logs.NewLogger()
  23. logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log"}`)
  24. logxMqtt = logs.NewLogger()
  25. logxMqtt.SetLogger(logs.AdapterFile, `{"filename":"logs/Mqtt/logx.log"}`)
  26. logxData = logs.NewLogger()
  27. logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log"}`)
  28. logxOrm = logs.NewLogger()
  29. logxOrm.SetLogger(logs.AdapterFile, `{"filename":"logs/Orm/logx.log"}`)
  30. if !Test {
  31. orm2.DebugLog = orm2.NewLog(logxOrm)
  32. }
  33. //
  34. // 测试 日志分割
  35. //go func() {
  36. // t := 1
  37. // orm2.DebugLog.Println("==========DebugLog=========")
  38. // for true {
  39. // t +=1
  40. // orm2.DebugLog.Println("DebugLog:",t)
  41. // time.Sleep(time.Second * 1)
  42. // }
  43. //}()
  44. //go TimeTask.OrmLog_MonitorScanStatus()
  45. }
  46. func Println(format string, v ...interface{}) {
  47. if Test {
  48. fmt.Println(format, v)
  49. }
  50. logx.Info(format, v)
  51. }
  52. func PrintlnError(format string, v ...interface{}) {
  53. if Test {
  54. fmt.Println(format, v)
  55. }
  56. logxE.Error(format, v)
  57. logx.Info(format, v)
  58. }
  59. func PrintlnMqtt(str string) {
  60. if Test {
  61. fmt.Println(str)
  62. }
  63. logxMqtt.Info(str)
  64. }
  65. func PrintlnData(str string) {
  66. if Test {
  67. fmt.Println(str)
  68. }
  69. logxData.Info(str)
  70. }
  71. //func Println(a ...interface{}) {
  72. // if test {
  73. // fmt.Printf("=>", a)
  74. // }
  75. // logx.Info(">", a)
  76. //}
  77. // 日志
  78. // logs.Println(time.Now().Format("2006-01-02 15:04:05"), "=>", a)
  79. // 重要
  80. // logs.Println("MqttServer", " 存在报警 跳过:", string(msg))
  81. // 严重
  82. // logs.Println("MqttServer", " 存在报警 跳过:", string(msg))