68 lines
1.4 KiB
Plaintext
68 lines
1.4 KiB
Plaintext
package logUtil
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
impl_console "goutil/logUtil/impl-console"
|
|
impl_es "goutil/logUtil/impl-es"
|
|
impl_localfile "goutil/logUtil/impl-localfile"
|
|
)
|
|
|
|
func TestAllLog(t *testing.T) {
|
|
file, _ := exec.LookPath(os.Args[0])
|
|
path, _ := filepath.Abs(file)
|
|
logPath := filepath.Dir(path)
|
|
|
|
GetLocalFileLog().SetLogPath(logPath)
|
|
|
|
//添加控制台日志
|
|
consoleLog := impl_console.NewLogger()
|
|
|
|
//添加es日志
|
|
urls := []string{"http://10.1.0.71:9101/"}
|
|
eslog, err := impl_es.NewLogger(urls, "", "", "es_log_test", "les_log_test_innerid", nil)
|
|
if err != nil {
|
|
t.Error("esLog 创建失败")
|
|
}
|
|
SettingLogs([]ILog{consoleLog, eslog, impl_localfile.NewLogger()})
|
|
|
|
for i := 1; i < 10; i++ {
|
|
InfoLog("Info记录")
|
|
InfoLog("Info记录2:%v %v", i, time.Now())
|
|
|
|
DebugLog("Debug记录")
|
|
DebugLog("Debug记录2:%v %v", i, time.Now())
|
|
|
|
WarnLog("Warn记录")
|
|
WarnLog("Warn记录2:%v %v", i, time.Now())
|
|
|
|
ErrorLog("Error记录")
|
|
ErrorLog("ErrorLog记录2:%v %v", i, time.Now())
|
|
|
|
FatalLog("Fatal记录")
|
|
FatalLog("Fatal记录2:%v %v", i, time.Now())
|
|
}
|
|
|
|
time.Sleep(time.Second * 5)
|
|
|
|
Close(true)
|
|
}
|
|
|
|
func BenchmarkInfoLog(b *testing.B) {
|
|
file, _ := exec.LookPath(os.Args[0])
|
|
path, _ := filepath.Abs(file)
|
|
logPath := filepath.Dir(path)
|
|
|
|
GetLocalFileLog().SetLogPath(logPath)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
DebugLog("Debug 记录")
|
|
InfoLog("info记录 :%v", time.Now())
|
|
}
|
|
Close(true)
|
|
}
|