Prechádzať zdrojové kódy

Fixed #2

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana 10 rokov pred
rodič
commit
cc4f298601
1 zmenil súbory, kde vykonal 11 pridanie a 6 odobranie
  1. 11 6
      log/log.go

+ 11 - 6
log/log.go

@@ -42,9 +42,9 @@ func New(prefix string) (l *Logger) {
 	l = &Logger{
 		level:  INFO,
 		prefix: prefix,
+		out:    colorable.NewColorableStdout(),
+		err:    colorable.NewColorableStderr(),
 	}
-	l.SetOutput(colorable.NewColorableStdout())
-	l.err = colorable.NewColorableStderr()
 	return
 }
 
@@ -59,17 +59,18 @@ func (l *Logger) SetLevel(v Level) {
 func (l *Logger) SetOutput(w io.Writer) {
 	l.out = w
 	l.err = w
-	initLevels()
-	color.Disable()
 
 	switch w := w.(type) {
 	case *os.File:
 		if isatty.IsTerminal(w.Fd()) {
 			color.Enable()
 		}
-		// NOTE: Reintialize levels to reflect color enable/disable.
-		initLevels()
+	default:
+		color.Disable()
 	}
+
+	// NOTE: Reintialize levels to reflect color enable/disable call.
+	initLevels()
 }
 
 func (l *Logger) Print(msg interface{}, args ...interface{}) {
@@ -180,3 +181,7 @@ func initLevels() {
 		color.RedBg("FATAL"),
 	}
 }
+
+func init() {
+	initLevels()
+}