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

62 lines
1.5 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. "testing"
  7. "time"
  8. )
  9. func TestGetLogger(t *testing.T) {
  10. // 新建 channel 大小为128 标识为nds 日志通道 , Get 的方法 默认带 console 和 file 输出
  11. l := Get("nds", 128).SetAdapter(LevelAll, AdapterElasticSearch)
  12. l.Debug("我正在调试")
  13. l.Critical("出错了")
  14. // 复用 nds 的日志通道
  15. Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
  16. Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
  17. // 新建 channel 大小为默认 标识为wifi 日志通道 , GetEs 的方法 默认带 console 和 file 和 elatisearch 输出
  18. GetEs("wifi")
  19. for i := 0; i < 10; i++ {
  20. Get("wifi").Warning("Warning")
  21. Get("wifi").Warn("Warn")
  22. Get("wifi").Debug("Debug")
  23. Get("wifi").Error("Error")
  24. Get("wifi").Notice("Notice")
  25. Get("wifi").Info("Info")
  26. Get("wifi").Alert("Alert")
  27. }
  28. Get("wifi").Critical("neoweiwoewe")
  29. }
  30. func TestGetAliLs(t *testing.T) {
  31. lable := "test_alils"
  32. l := GetAli(lable).Async(128)
  33. for i := 0; i < 2; i++ {
  34. l.Info("Info")
  35. l.Debug("Debug")
  36. l.Warn("Warn")
  37. l.Warning("Warning")
  38. l.Error("Error")
  39. l.Error("Error\n\n 测试换行")
  40. l.Warn("Warn")
  41. }
  42. Close(lable, lable, lable)
  43. }
  44. func TestDropAdapter(t *testing.T) {
  45. SetAdapter(LevelAll, AdapterAliLs)
  46. DropAdapter(AdapterAliLs)
  47. Informational(errors.New("he hello"))
  48. SetAdapter(LevelAll, AdapterAliLs)
  49. Debug(errors.New("he hello"))
  50. CloseAll()
  51. }