Explorar o código

Added colors

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana %!s(int64=10) %!d(string=hai) anos
pai
achega
5562382f63
Modificáronse 2 ficheiros con 13 adicións e 8 borrados
  1. 12 7
      log/log.go
  2. 1 1
      log/log_test.go

+ 12 - 7
log/log.go

@@ -1,10 +1,13 @@
 package log
 
 import (
+	"bytes"
 	"fmt"
 	"io"
 	"os"
 	"sync"
+
+	"github.com/labstack/gommon/color"
 )
 
 type (
@@ -32,13 +35,13 @@ const (
 
 var (
 	levels = []string{
-		"trace",
-		"debug",
-		"info",
-		"notice",
-		"warn",
-		"error",
-		"fatal",
+		color.Cyan("TRACE"),
+		color.Blue("DEBUG"),
+		color.Green("INFO"),
+		color.Magenta("NOTICE"),
+		color.Yellow("WARN"),
+		color.Red("ERROR"),
+		color.RedBg("FATAL"),
 	}
 )
 
@@ -61,7 +64,9 @@ func (l *Log) SetOutput(w io.Writer) {
 
 	switch w.(type) {
 	case *os.File:
+	case *bytes.Buffer:
 		l.lock = true
+		color.Disable()
 	default:
 		l.lock = false
 	}

+ 1 - 1
log/log_test.go

@@ -4,7 +4,7 @@ import "testing"
 
 func TestLog(t *testing.T) {
 	l := New("log")
-	l.SetLevel(Warn)
+	l.SetLevel(Trace)
 	l.Trace("trace")
 	l.Debug("debug")
 	l.Info("info")