소스 검색

API changed

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana 9 년 전
부모
커밋
43358a791b
2개의 변경된 파일82개의 추가작업 그리고 53개의 파일을 삭제
  1. 70 46
      log/log.go
  2. 12 7
      log/log_test.go

+ 70 - 46
log/log.go

@@ -22,10 +22,8 @@ type (
 )
 )
 
 
 const (
 const (
-	TRACE = iota
-	DEBUG
+	DEBUG = iota
 	INFO
 	INFO
-	NOTICE
 	WARN
 	WARN
 	ERROR
 	ERROR
 	FATAL
 	FATAL
@@ -70,42 +68,54 @@ func (l *Logger) SetOutput(w io.Writer) {
 	initLevels()
 	initLevels()
 }
 }
 
 
-func (l *Logger) Print(msg interface{}, args ...interface{}) {
-	f := fmt.Sprintf("%s", msg)
-	fmt.Fprintf(l.out, f, args...)
+func (l *Logger) Print(i interface{}) {
+	fmt.Println(i)
 }
 }
 
 
-func (l *Logger) Println(msg interface{}, args ...interface{}) {
-	f := fmt.Sprintf("%s\n", msg)
+func (l *Logger) Printf(format string, args ...interface{}) {
+	f := fmt.Sprintf("%s\n", format)
 	fmt.Fprintf(l.out, f, args...)
 	fmt.Fprintf(l.out, f, args...)
 }
 }
 
 
-func (l *Logger) Trace(msg interface{}, args ...interface{}) {
-	l.log(TRACE, l.out, msg, args...)
+func (l *Logger) Debug(i interface{}) {
+	l.log(DEBUG, i)
+}
+
+func (l *Logger) Debugf(format string, args ...interface{}) {
+	l.log(DEBUG, format, args...)
+}
+
+func (l *Logger) Info(i interface{}) {
+	l.log(INFO, i)
+}
+
+func (l *Logger) Infof(format string, args ...interface{}) {
+	l.log(INFO, format, args...)
 }
 }
 
 
-func (l *Logger) Debug(msg interface{}, args ...interface{}) {
-	l.log(DEBUG, l.out, msg, args...)
+func (l *Logger) Warn(i interface{}) {
+	l.log(WARN, i)
 }
 }
 
 
-func (l *Logger) Info(msg interface{}, args ...interface{}) {
-	l.log(INFO, l.out, msg, args...)
+func (l *Logger) Warnf(format string, args ...interface{}) {
+	l.log(WARN, format, args...)
 }
 }
 
 
-func (l *Logger) Notice(msg interface{}, args ...interface{}) {
-	l.log(NOTICE, l.out, msg, args...)
+func (l *Logger) Error(i interface{}) {
+	l.log(ERROR, i)
 }
 }
 
 
-func (l *Logger) Warn(msg interface{}, args ...interface{}) {
-	l.log(WARN, l.out, msg, args...)
+func (l *Logger) Errorf(format string, args ...interface{}) {
+	l.log(ERROR, format, args...)
 }
 }
 
 
-func (l *Logger) Error(msg interface{}, args ...interface{}) {
-	l.log(ERROR, l.out, msg, args...)
+func (l *Logger) Fatal(i interface{}) {
+	l.log(FATAL, i)
+	os.Exit(1)
 }
 }
 
 
-func (l *Logger) Fatal(msg interface{}, args ...interface{}) {
-	l.log(FATAL, l.out, msg, args...)
+func (l *Logger) Fatalf(format string, args ...interface{}) {
+	l.log(FATAL, format, args...)
 	os.Exit(1)
 	os.Exit(1)
 }
 }
 
 
@@ -121,59 +131,73 @@ func SetOutput(w io.Writer) {
 	global.SetOutput(w)
 	global.SetOutput(w)
 }
 }
 
 
-func Print(msg interface{}, args ...interface{}) {
-	global.Print(msg, args...)
+func Print(i interface{}) {
+	global.Print(i)
+}
+
+func Printf(format string, args ...interface{}) {
+	global.Printf(format, args...)
+}
+
+func Debug(i interface{}) {
+	global.Debug(i)
+}
+
+func Debugf(format string, args ...interface{}) {
+	global.Debugf(format, args...)
 }
 }
 
 
-func Println(msg interface{}, args ...interface{}) {
-	global.Println(msg, args...)
+func Info(i interface{}) {
+	global.Info(i)
 }
 }
 
 
-func Trace(msg interface{}, args ...interface{}) {
-	global.Trace(msg, args...)
+func Infof(format string, args ...interface{}) {
+	global.Infof(format, args...)
 }
 }
 
 
-func Debug(msg interface{}, args ...interface{}) {
-	global.Debug(msg, args...)
+func Warn(i interface{}) {
+	global.Warn(i)
 }
 }
 
 
-func Info(msg interface{}, args ...interface{}) {
-	global.Info(msg, args...)
+func Warnf(format string, args ...interface{}) {
+	global.Warnf(format, args...)
 }
 }
 
 
-func Notice(msg interface{}, args ...interface{}) {
-	global.Notice(msg, args...)
+func Error(i interface{}) {
+	global.Error(i)
 }
 }
 
 
-func Warn(msg interface{}, args ...interface{}) {
-	global.Warn(msg, args...)
+func Errorf(format string, args ...interface{}) {
+	global.Errorf(format, args...)
 }
 }
 
 
-func Error(msg interface{}, args ...interface{}) {
-	global.Error(msg, args...)
+func Fatal(i interface{}) {
+	global.Fatal(i)
 }
 }
 
 
-func Fatal(msg interface{}, args ...interface{}) {
-	global.Fatal(msg, args...)
+func Fatalf(format string, args ...interface{}) {
+	global.Fatalf(format, args...)
 }
 }
 
 
-func (l *Logger) log(v Level, w io.Writer, msg interface{}, args ...interface{}) {
+func (l *Logger) log(v Level, format interface{}, args ...interface{}) {
 	l.mu.Lock()
 	l.mu.Lock()
 	defer l.mu.Unlock()
 	defer l.mu.Unlock()
 
 
 	if v >= l.level {
 	if v >= l.level {
-		// TODO: Improve performance
-		f := fmt.Sprintf("%s|%s|%v\n", levels[v], l.prefix, msg)
-		fmt.Fprintf(w, f, args...)
+		if len(args) == 0 {
+			fmt.Println(format)
+		} else {
+			// TODO: Improve performance
+			f := fmt.Sprintf("%s|%s|%v\n", levels[v], l.prefix, format)
+			fmt.Fprintf(l.out, f, args...)
+		}
 	}
 	}
 }
 }
 
 
 func initLevels() {
 func initLevels() {
 	levels = []string{
 	levels = []string{
-		color.Cyan("TRACE"),
 		color.Blue("DEBUG"),
 		color.Blue("DEBUG"),
 		color.Green("INFO"),
 		color.Green("INFO"),
-		color.Magenta("NOTICE"),
 		color.Yellow("WARN"),
 		color.Yellow("WARN"),
 		color.Red("ERROR"),
 		color.Red("ERROR"),
 		color.RedBg("FATAL"),
 		color.RedBg("FATAL"),

+ 12 - 7
log/log_test.go

@@ -11,27 +11,32 @@ func TestLog(t *testing.T) {
 	l := New("test")
 	l := New("test")
 	b := new(bytes.Buffer)
 	b := new(bytes.Buffer)
 	l.SetOutput(b)
 	l.SetOutput(b)
-	test(l, TRACE, t)
-	assert.Contains(t, b.String(), "trace")
+	test(l, DEBUG, t)
+	assert.Contains(t, b.String(), "debug")
+	assert.Contains(t, b.String(), "debugf")
+	assert.Contains(t, b.String(), "warn")
+	assert.Contains(t, b.String(), "warnf")
 	// assert.Contains(t, b.String(), "fatal")
 	// assert.Contains(t, b.String(), "fatal")
 
 
 	b.Reset()
 	b.Reset()
 	SetOutput(b)
 	SetOutput(b)
-	test(global, NOTICE, t)
+	test(global, WARN, t)
 	assert.NotContains(t, b.String(), "info")
 	assert.NotContains(t, b.String(), "info")
-	assert.Contains(t, b.String(), "notice")
+	assert.Contains(t, b.String(), "warn")
 	// assert.Contains(t, b.String(), "fatal")
 	// assert.Contains(t, b.String(), "fatal")
 }
 }
 
 
 func test(l *Logger, v Level, t *testing.T) {
 func test(l *Logger, v Level, t *testing.T) {
 	l.SetLevel(v)
 	l.SetLevel(v)
 	l.Print("print")
 	l.Print("print")
-	l.Println("println")
-	l.Trace("trace")
+	l.Printf("print%s", "f")
 	l.Debug("debug")
 	l.Debug("debug")
+	l.Debugf("debug%s", "f")
 	l.Info("info")
 	l.Info("info")
-	l.Notice("notice")
+	l.Infof("info%s", "f")
 	l.Warn("warn")
 	l.Warn("warn")
+	l.Warnf("warn%s", "f")
 	l.Error("error")
 	l.Error("error")
+	l.Errorf("error%s", "f")
 	// l.Fatal("fatal")
 	// l.Fatal("fatal")
 }
 }