logger_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package logger
  2. import (
  3. "git.shuncheng.lu/bigthing/gocommon/pkg/conf"
  4. "testing"
  5. "time"
  6. )
  7. func testMock() {
  8. config := map[string]string{
  9. "project_log": "/data/log/go-template/go-template.log",
  10. "access_log": "/data/log/go-template/access.log",
  11. "task_log": "/data/log/go-template/task.log",
  12. "third_log": "/data/log/go-template/third.log",
  13. "monitor_log": "/data/log/go-template/monitor.log",
  14. }
  15. conf.MustValue = func(section, key string, defaultVal ...string) string {
  16. return config[key]
  17. }
  18. }
  19. func TestLogger(t *testing.T) {
  20. testMock()
  21. err := Init()
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. Infof("hello, %s!", "Infof")
  26. Errorf("hello, %s!", "Errorf")
  27. Debugf("hello, %s!", "Debugf")
  28. Warnf("hello, %s!", "Warnf")
  29. ctx := NewTraceIdContext()
  30. Infoc(ctx, "hello, %s!", "Infof")
  31. Errorc(ctx, "hello, %s!", "Errorf")
  32. Debugc(ctx, "hello, %s!", "Debugf")
  33. Warnc(ctx, "hello, %s!", "Warnf")
  34. /*Fatalc(ctx, "hello, %s!", "Fatalf")*/
  35. TaskInfo("ts1", 1, 1, "测试", 111)
  36. ThirdLog("http://xxx.ts1", 200, 50, 121, "111")
  37. AccessInfof("access : %s", "hello access info")
  38. AccessErrorf("access : %s", "hello access error")
  39. MonitorErrorf(1, uint64(time.Now().Unix()), "异常: %s", "monitor")
  40. }