diff --git a/log/level_test.go b/log/level_test.go index d7d42bce..e82a4bdb 100644 --- a/log/level_test.go +++ b/log/level_test.go @@ -1,6 +1,8 @@ package log import ( + "encoding/json" + "os" "testing" ) @@ -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) }