Skip to content

Commit

Permalink
test log level and add some unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfstudy committed Nov 13, 2018
1 parent 6d28abb commit 69dc782
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions log/level_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package log

import (
"encoding/json"
"os"
"testing"
)

Expand All @@ -16,4 +18,33 @@ func TestGetLevel(t *testing.T) {
if num != 7 {
t.Errorf("defaultLogLevel set failed: %d\n", num)
}

initLogLevel("error")
Debug("my book is bought in the year of ", 2016)
Info("this %s cat is %v years old", "yellow", 3)
Notice("Notice log")
Warn("json is a type of kv like", map[string]int{"key": 2016})
Error("error log")
Critical("critical log")
Alert("alert log")
Emergency("emergency log")
}

func initLogLevel(level string) {
fileName := "/tmp/test.log"

logConf := struct {
FileName string `json:"filename"`
Level int `json:"level"`
}{
FileName: fileName,
Level: GetLevel(level),
}

configuration, err := json.Marshal(logConf)
if err != nil {
panic(err)
}
Init(string(configuration))
os.Remove(fileName)
}

0 comments on commit 69dc782

Please sign in to comment.