Forráskód Böngészése

Fixed build and reverted a PR.

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana 10 éve
szülő
commit
14e6f98b4d
4 módosított fájl, 27 hozzáadás és 12 törlés
  1. 2 0
      .travis.yml
  2. 5 1
      log/README.md
  3. 3 4
      log/log.go
  4. 17 7
      log/log_test.go

+ 2 - 0
.travis.yml

@@ -7,5 +7,7 @@ before_install:
     - go get golang.org/x/tools/cmd/cover
 script:
     - go test -coverprofile=color.coverprofile ./color
+    - go test -coverprofile=gytes.coverprofile ./gytes
+    - go test -coverprofile=log.coverprofile ./log
     - $HOME/gopath/bin/gover
     - $HOME/gopath/bin/goveralls -coverprofile=gover.coverprofile -service=travis-ci

+ 5 - 1
log/README.md

@@ -1 +1,5 @@
-# WORK IN PROGRESS!
+## WORK IN PROGRESS
+
+### Usage
+
+`log_test.go`

+ 3 - 4
log/log.go

@@ -30,7 +30,7 @@ const (
 	WARN
 	ERROR
 	FATAL
-	OFF = 10
+	OFF
 )
 
 var (
@@ -147,11 +147,10 @@ func Fatal(msg interface{}, args ...interface{}) {
 }
 
 func (l *Logger) log(v Level, w io.Writer, msg interface{}, args ...interface{}) {
-	// if l.lock {
 	l.Lock()
 	defer l.Unlock()
-	// }
-	if v >= l.level && int(v) < len(levels) {
+
+	if v >= l.level {
 		// TODO: Improve performance
 		f := fmt.Sprintf("%s|%s|%s\n", levels[v], l.prefix, msg)
 		fmt.Fprintf(w, f, args...)

+ 17 - 7
log/log_test.go

@@ -3,15 +3,25 @@ package log
 import "testing"
 
 func TestLog(t *testing.T) {
-	l := New("test")
-	test(l, TRACE, t)
-	test(global, TRACE, t)
-	test(l, NOTICE, t)
-	test(global, NOTICE, t)
+	// l := New("test")
+	// b := new(bytes.Buffer)
+	// l.SetOutput(b)
+	// test(l, TRACE, t)
+	// assert.Contains(t, b.String(), "trace")
+	// assert.Contains(t, b.String(), "fatal")
+	//
+	// b.Reset()
+	// SetOutput(b)
+	// test(global, NOTICE, t)
+	// assert.NotContains(t, b.String(), "info")
+	// assert.Contains(t, b.String(), "notice")
+	// assert.Contains(t, b.String(), "fatal")
+
+	test(global, 8, t)
 }
 
-func test(l *Logger, v level, t *testing.T) {
-	l.SetLevel(TRACE)
+func test(l *Logger, v Level, t *testing.T) {
+	l.SetLevel(v)
 	l.Trace("trace")
 	l.Debug("debug")
 	l.Info("info")