You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.3 KiB

  1. package grlogs
  2. import (
  3. "errors"
  4. _ "golib.gaore.com/GaoreGo/haiwai-grlogs/v2/logs/alils"
  5. _ "golib.gaore.com/GaoreGo/haiwai-grlogs/v2/logs/es"
  6. "os"
  7. "sync"
  8. "testing"
  9. "time"
  10. )
  11. func TestGetLogger(t *testing.T) {
  12. // 新建 channel 大小为128 标识为nds 日志通道 , Get 的方法 默认带 console 和 file 输出
  13. l := Get("nds", 128).SetAdapter(LevelAll, AdapterElasticSearch)
  14. l.Debug("我正在调试")
  15. l.Critical("出错了")
  16. // 复用 nds 的日志通道
  17. Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
  18. Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
  19. // 新建 channel 大小为默认 标识为wifi 日志通道 , GetEs 的方法 默认带 console 和 file 和 elatisearch 输出
  20. GetEs("wifi")
  21. for i := 0; i < 10; i++ {
  22. Get("wifi").Warning("Warning")
  23. Get("wifi").Warn("Warn")
  24. Get("wifi").Debug("Debug")
  25. Get("wifi").Error("Error")
  26. Get("wifi").Notice("Notice")
  27. Get("wifi").Info("Info")
  28. Get("wifi").Alert("Alert")
  29. }
  30. Get("wifi").Critical("neoweiwoewe")
  31. }
  32. func TestGetAliLs(t *testing.T) {
  33. lable := "test_alils"
  34. l := GetAli(lable).Async(128)
  35. for i := 0; i < 2; i++ {
  36. l.Info("Info")
  37. l.Debug("Debug")
  38. l.Warn("Warn")
  39. l.Warning("Warning")
  40. l.Error("Error")
  41. l.Error("Error\n\n 测试换行")
  42. l.Warn("Warn")
  43. }
  44. time.Sleep(time.Hour * 1)
  45. }
  46. func TestDropAdapter(t *testing.T) {
  47. SetAdapter(LevelAll, AdapterAliLs)
  48. DropAdapter(AdapterAliLs)
  49. Informational(errors.New("he hello"))
  50. SetAdapter(LevelAll, AdapterAliLs)
  51. Debug(errors.New("he hello"))
  52. CloseAll()
  53. }
  54. func TestNew(t *testing.T) {
  55. os.Setenv("CENTER_RUNMODE", "dev")
  56. os.Setenv("GRLOG_APP_NAME", "yoda")
  57. os.Setenv("GRLOG_ALILS_DEBUG", "on")
  58. t.Log("GRLOG_INTERNET:" + os.Getenv("GRLOG_INTERNET"))
  59. t.Log("GAORE_ENVIRONMENT:" + os.Getenv("GAORE_ENVIRONMENT"))
  60. wg := sync.WaitGroup{}
  61. for i := 0; i < 10; i++ {
  62. wg.Add(1)
  63. go func(i int) {
  64. GetAli("ok").Info("%d", i)
  65. time.Sleep(10 * time.Second)
  66. wg.Done()
  67. }(i)
  68. }
  69. for i := 0; i < 10; i++ {
  70. GetAli("ok").Debug("aaaaaa%d", i)
  71. }
  72. wg.Wait()
  73. }
  74. func TestGetEs(t *testing.T) {
  75. wg := sync.WaitGroup{}
  76. for i := 0; i < 10; i++ {
  77. wg.Add(1)
  78. go func(i int) {
  79. GetEs("ok").Debug("%d", i)
  80. time.Sleep(time.Second * 10)
  81. wg.Done()
  82. }(i)
  83. }
  84. for i := 0; i < 10; i++ {
  85. GetEs("ok").Debug("aaaaaa%d", i)
  86. }
  87. wg.Wait()
  88. }