Browse Source

Switch from golang log to coreos/go-log

David Fisher 12 years ago
parent
commit
a121cbb721
1 changed files with 14 additions and 15 deletions
  1. 14 15
      util.go

+ 14 - 15
util.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"fmt"
 	"io"
-	"log"
 	"net"
 	"net/http"
 	"net/url"
@@ -15,6 +14,7 @@ import (
 	"time"
 
 	"github.com/coreos/etcd/web"
+	"github.com/coreos/go-log/log"
 )
 
 //--------------------------------------
@@ -141,41 +141,40 @@ func check(err error) {
 var logger *log.Logger
 
 func init() {
-	logger = log.New(os.Stdout, "[etcd] ", log.Lmicroseconds)
+	logger = log.New("etcd", false,
+		log.CombinedSink(os.Stdout, "[%s] %s %-9s | %s\n", []string{"prefix", "time", "priority", "message"}))
 }
 
-func infof(msg string, v ...interface{}) {
-	logger.Printf("INFO "+msg+"\n", v...)
+func infof(format string, v ...interface{}) {
+	logger.Infof(format, v...)
 }
 
-func debugf(msg string, v ...interface{}) {
+func debugf(format string, v ...interface{}) {
 	if verbose {
-		logger.Printf("DEBUG "+msg+"\n", v...)
+		logger.Debugf(format, v...)
 	}
 }
 
 func debug(v ...interface{}) {
 	if verbose {
-		logger.Println("DEBUG " + fmt.Sprint(v...))
+		logger.Debug(v...)
 	}
 }
 
-func warnf(msg string, v ...interface{}) {
-	logger.Printf("WARN  "+msg+"\n", v...)
+func warnf(format string, v ...interface{}) {
+	logger.Warningf(format, v...)
 }
 
 func warn(v ...interface{}) {
-	logger.Println("WARN " + fmt.Sprint(v...))
+	logger.Warning(v...)
 }
 
-func fatalf(msg string, v ...interface{}) {
-	logger.Printf("FATAL "+msg+"\n", v...)
-	os.Exit(1)
+func fatalf(format string, v ...interface{}) {
+	logger.Fatalf(format, v...)
 }
 
 func fatal(v ...interface{}) {
-	logger.Println("FATAL " + fmt.Sprint(v...))
-	os.Exit(1)
+	logger.Fatalln(v...)
 }
 
 //--------------------------------------