github.com/MasterDimmy/zipologger@v0.3.8/logger_test.go (about) 1 package zipologger 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 func subFunc(a string) { 10 logger.Print("test from subFunc: " + a) 11 } 12 13 func subFunc2() { 14 subFunc("c") 15 } 16 17 func Test_callerDepth(t *testing.T) { 18 defer Wait() 19 20 SetAlsoToStdout(true) 21 22 logger = NewLogger("test", 1, 1, 1, true) 23 logger.Print("test from main") 24 25 go func() { 26 logger.Print("test from go func") 27 }() 28 29 subFunc("a") 30 31 func() { 32 logger.Print("test from func ") 33 subFunc("b") 34 }() 35 36 subFunc2() 37 } 38 39 func Test_println(t *testing.T) { 40 defer Wait() 41 42 SetAlsoToStdout(true) 43 44 logger = NewLogger("test", 1, 1, 1, true) 45 46 logger.Println("1") 47 48 logger.Println("1", "2") 49 50 d := 4 51 logger.Println("1", 3) 52 53 logger.Println(3, "2", d) 54 55 t.Log("wait 1") 56 Wait() 57 t.Log("wait 2") 58 Wait() 59 } 60 61 func Test_2logger_by_suffix(t *testing.T) { 62 defer Wait() 63 64 SetAlsoToStdout(false) 65 66 for i := 0; i < 10000; i++ { 67 l1 := GetLoggerBySuffix("a.log", "./logs/", 1, 1, 1, false) 68 l2 := GetLoggerBySuffix("b.log", "./logs/", 1, 1, 1, false) 69 70 //t.Log("print 1") 71 72 st := l2.Printf("%d aaaa - %s", i, time.Now().String()) 73 if i%100 == 0 { 74 t.Log(st) 75 } 76 77 //t.Log("flush 1") 78 79 l2.Flush() 80 81 //t.Log("print 2") 82 83 l1.Print("bbb") 84 85 //t.Log("flush 2") 86 87 l1.Flush() 88 l2.Flush() 89 l1.Wait() 90 l2.Wait() 91 l1.Wait() 92 l1.Wait() 93 } 94 95 } 96 97 func Test_CloseFiles(t *testing.T) { 98 defer Wait() 99 100 sw := GetLoggerBySuffix(fmt.Sprintf("123123.log"), "./logs/", 1, 1, 1, false) 101 sw.Print("123123123") 102 103 Wait() 104 105 SetAlsoToStdout(false) 106 107 for i := 0; i < 100; i++ { 108 l1 := GetLoggerBySuffix(fmt.Sprintf("a_%d.log", i), "./logs/", 1, 1, 1, false) 109 l1.Printf("%d a", i) 110 } 111 112 Wait() 113 Wait() 114 }