-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger_test.go
46 lines (38 loc) · 1012 Bytes
/
logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package logger
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
func TestInitLog(t *testing.T) {
os.Setenv("DTM_DEBUG", "1")
InitLog("debug")
Debugf("a debug msg")
Infof("a info msg")
Warnf("a warn msg")
Errorf("a error msg")
FatalfIf(false, "nothing")
FatalIfError(nil)
InitLog2("debug", "test.log,stderr", 0, "")
Debugf("a debug msg to console and file")
InitLog2("debug", "test2.log,/tmp/dtm-test1.log,/tmp/dtm-test.log,stdout,stderr", 1,
"{\"maxsize\": 1, \"maxage\": 1, \"maxbackups\": 1, \"compress\": false}")
Debugf("a debug msg to /tmp/dtm-test.log and test2.log and stdout and stderr")
// _ = os.Remove("test.log")
}
func TestWithLogger(t *testing.T) {
logger := zap.NewExample().Sugar()
WithLogger(logger)
Debugf("a debug msg")
Infof("a info msg")
Warnf("a warn msg")
Errorf("a error msg")
FatalfIf(false, "nothing")
FatalIfError(nil)
}
func TestCover(t *testing.T) {
sin := lumberjackSink{}
err := sin.Sync()
assert.Nil(t, err)
}