LogPrintln.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 logxWData *logs.BeeLogger
  12. var logxMqtt *logs.BeeLogger
  13. var logxData *logs.BeeLogger
  14. var LogxOrm *logs.BeeLogger
  15. func init() {
  16. if runtime.GOOS == "windows" {
  17. Test = true
  18. } else {
  19. Test = false
  20. }
  21. logx = logs.NewLogger()
  22. logx.SetLogger(logs.AdapterFile, `{"filename":"logs/logx/logx.log","MaxDays":30}`)
  23. logxE = logs.NewLogger()
  24. logxE.SetLogger(logs.AdapterFile, `{"filename":"logs/logxE/logx.log","MaxDays":180}`)
  25. logxMqtt = logs.NewLogger()
  26. logxMqtt.SetLogger(logs.AdapterFile, `{"filename":"logs/Mqtt/logx.log","MaxDays":30}`)
  27. logxData = logs.NewLogger()
  28. logxData.SetLogger(logs.AdapterFile, `{"filename":"logs/Data/logx.log","MaxDays":7}`)
  29. logxWData = logs.NewLogger()
  30. logxWData.SetLogger(logs.AdapterFile, `{"filename":"logs/logxWData/logx.log","MaxDays":300}`)
  31. LogxOrm = logs.NewLogger()
  32. LogxOrm.SetLogger(logs.AdapterFile, `{"filename":"logs/Orm/logx.log","MaxDays":7}`)
  33. if !Test {
  34. orm2.DebugLog = orm2.NewLog(LogxOrm)
  35. }
  36. //
  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. if Test {
  51. fmt.Println(format, v)
  52. }
  53. logx.Info(format, v)
  54. }
  55. func PrintlnError(format string, v ...interface{}) {
  56. if Test {
  57. fmt.Println(format, v)
  58. }
  59. logxE.Error(format, v)
  60. logx.Info(format, v)
  61. }
  62. func PrintlnMqtt(str string) {
  63. if Test {
  64. fmt.Println(str)
  65. }
  66. logxMqtt.Info(str)
  67. }
  68. func PrintlnWData(format string, v ...interface{}) {
  69. logx.Info(format, v)
  70. }
  71. func PrintlnData(str string) {
  72. if Test {
  73. fmt.Println(str)
  74. }
  75. logxData.Info(str)
  76. }
  77. //func Println(a ...interface{}) {
  78. // if test {
  79. // fmt.Printf("=>", a)
  80. // }
  81. // logx.Info(">", a)
  82. //}
  83. // 日志
  84. // logs.Println(time.Now().Format("2006-01-02 15:04:05"), "=>", a)
  85. // 重要
  86. // logs.Println("MqttServer", " 存在报警 跳过:", string(msg))
  87. // 严重
  88. // logs.Println("MqttServer", " 存在报警 跳过:", string(msg))