| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package logger
- import (
- "git.shuncheng.lu/bigthing/gocommon/pkg/conf"
- "testing"
- "time"
- )
- func testMock() {
- config := map[string]string{
- "project_log": "/data/log/go-template/go-template.log",
- "access_log": "/data/log/go-template/access.log",
- "task_log": "/data/log/go-template/task.log",
- "third_log": "/data/log/go-template/third.log",
- "monitor_log": "/data/log/go-template/monitor.log",
- }
- conf.MustValue = func(section, key string, defaultVal ...string) string {
- return config[key]
- }
- }
- func TestLogger(t *testing.T) {
- testMock()
- err := Init()
- if err != nil {
- t.Fatal(err)
- }
- Infof("hello, %s!", "Infof")
- Errorf("hello, %s!", "Errorf")
- Debugf("hello, %s!", "Debugf")
- Warnf("hello, %s!", "Warnf")
- ctx := NewTraceIdContext()
- Infoc(ctx, "hello, %s!", "Infof")
- Errorc(ctx, "hello, %s!", "Errorf")
- Debugc(ctx, "hello, %s!", "Debugf")
- Warnc(ctx, "hello, %s!", "Warnf")
- /*Fatalc(ctx, "hello, %s!", "Fatalf")*/
- TaskInfo("ts1", 1, 1, "测试", 111)
- ThirdLog("http://xxx.ts1", 200, 50, 121, "111")
- AccessInfof("access : %s", "hello access info")
- AccessErrorf("access : %s", "hello access error")
- MonitorErrorf(1, uint64(time.Now().Unix()), "异常: %s", "monitor")
- }
|