Просмотр исходного кода

Log: Added Print and Println API

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana 10 лет назад
Родитель
Сommit
54eea1371d
2 измененных файлов с 21 добавлено и 1 удалено
  1. 19 1
      log/log.go
  2. 2 0
      log/log_test.go

+ 19 - 1
log/log.go

@@ -78,6 +78,16 @@ func (l *Logger) SetOutput(w io.Writer) {
 	}
 }
 
+func (l *Logger) Print(msg interface{}, args ...interface{}) {
+	f := fmt.Sprintf("%s", msg)
+	fmt.Fprintf(l.out, f, args...)
+}
+
+func (l *Logger) Println(msg interface{}, args ...interface{}) {
+	f := fmt.Sprintf("%s\n", msg)
+	fmt.Fprintf(l.out, f, args...)
+}
+
 func (l *Logger) Trace(msg interface{}, args ...interface{}) {
 	l.log(TRACE, l.out, msg, args...)
 }
@@ -118,6 +128,14 @@ func SetOutput(w io.Writer) {
 	global.SetOutput(w)
 }
 
+func Print(msg interface{}, args ...interface{}) {
+	global.Print(msg, args...)
+}
+
+func Println(msg interface{}, args ...interface{}) {
+	global.Println(msg, args...)
+}
+
 func Trace(msg interface{}, args ...interface{}) {
 	global.Trace(msg, args...)
 }
@@ -152,7 +170,7 @@ func (l *Logger) log(v Level, w io.Writer, msg interface{}, args ...interface{})
 
 	if v >= l.level {
 		// TODO: Improve performance
-		f := fmt.Sprintf("%s|%s|%s\n", levels[v], l.prefix, msg)
+		f := fmt.Sprintf("%s|%s|%v\n", levels[v], l.prefix, msg)
 		fmt.Fprintf(w, f, args...)
 	}
 }

+ 2 - 0
log/log_test.go

@@ -25,6 +25,8 @@ func TestLog(t *testing.T) {
 
 func test(l *Logger, v Level, t *testing.T) {
 	l.SetLevel(v)
+	l.Print("print")
+	l.Println("println")
 	l.Trace("trace")
 	l.Debug("debug")
 	l.Info("info")