高热共公日志库
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.

81 lines
1.8 KiB

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