No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

106 líneas
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("GRLOG_INTERNET", "public")
  56. os.Setenv("GAORE_ENVIRONMENT", "development")
  57. os.Setenv("CENTER_RUNMODE", "dev")
  58. os.Setenv("GRLOG_APP_NAME", "yoda")
  59. os.Setenv("GRLOG_ALILS_DEBUG", "on")
  60. t.Log(os.Getenv("GRLOG_INTERNET"))
  61. wg := sync.WaitGroup{}
  62. for i := 0; i < 10; i++ {
  63. wg.Add(1)
  64. go func(i int) {
  65. GetAli("ok").Info("%d", i)
  66. time.Sleep(10 * time.Second)
  67. wg.Done()
  68. }(i)
  69. }
  70. for i := 0; i < 10; i++ {
  71. GetAli("ok").Debug("aaaaaa%d", i)
  72. }
  73. wg.Wait()
  74. }
  75. func TestGetEs(t *testing.T) {
  76. wg := sync.WaitGroup{}
  77. for i := 0; i < 10; i++ {
  78. wg.Add(1)
  79. go func(i int) {
  80. GetEs("ok").Debug("%d", i)
  81. time.Sleep(time.Second * 10)
  82. wg.Done()
  83. }(i)
  84. }
  85. for i := 0; i < 10; i++ {
  86. GetEs("ok").Debug("aaaaaa%d", i)
  87. }
  88. wg.Wait()
  89. }