Browse Source

use infof instead of fmt.Printf

Fabrizio (Misto) Milo 12 years ago
parent
commit
3102420542
4 changed files with 10 additions and 10 deletions
  1. 2 3
      config.go
  2. 2 3
      etcd.go
  3. 2 4
      raft_server.go
  4. 4 0
      util.go

+ 2 - 3
config.go

@@ -2,7 +2,6 @@ package main
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
-	"fmt"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
@@ -52,7 +51,7 @@ func getInfo(path string) *Info {
 
 
 	info := parseInfo(infoPath)
 	info := parseInfo(infoPath)
 	if info != nil {
 	if info != nil {
-		fmt.Printf("Found node configuration in '%s'. Ignoring flags.\n", infoPath)
+		infof("Found node configuration in '%s'. Ignoring flags", infoPath)
 		return info
 		return info
 	}
 	}
 
 
@@ -65,7 +64,7 @@ func getInfo(path string) *Info {
 		fatalf("Unable to write info to file: %v", err)
 		fatalf("Unable to write info to file: %v", err)
 	}
 	}
 
 
-	fmt.Printf("Wrote node configuration to '%s'.\n", infoPath)
+	infof("Wrote node configuration to '%s'", infoPath)
 
 
 	return info
 	return info
 }
 }

+ 2 - 3
etcd.go

@@ -5,7 +5,6 @@ import (
 	"crypto/x509"
 	"crypto/x509"
 	"encoding/pem"
 	"encoding/pem"
 	"flag"
 	"flag"
-	"fmt"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/web"
 	"github.com/coreos/etcd/web"
 
 
@@ -158,7 +157,7 @@ func main() {
 		signal.Notify(c, os.Interrupt)
 		signal.Notify(c, os.Interrupt)
 		go func() {
 		go func() {
 			for sig := range c {
 			for sig := range c {
-				fmt.Printf("captured %v, stopping profiler and exiting..", sig)
+				infof("captured %v, stopping profiler and exiting..", sig)
 				pprof.StopCPUProfile()
 				pprof.StopCPUProfile()
 				os.Exit(1)
 				os.Exit(1)
 			}
 			}
@@ -254,7 +253,7 @@ func dialTimeout(network, addr string) (net.Conn, error) {
 // Start to listen and response client command
 // Start to listen and response client command
 func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
 func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
 	u, _ := url.Parse(info.EtcdURL)
 	u, _ := url.Parse(info.EtcdURL)
-	fmt.Printf("etcd server [%s] listening on %s\n", info.Name, u)
+	infof("etcd server [%s:%s]", info.Name, u)
 
 
 	etcdMux := http.NewServeMux()
 	etcdMux := http.NewServeMux()
 
 

+ 2 - 4
raft_server.go

@@ -7,7 +7,6 @@ import (
 	"fmt"
 	"fmt"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
-	"os"
 	"time"
 	"time"
 
 
 	"github.com/coreos/go-raft"
 	"github.com/coreos/go-raft"
@@ -88,8 +87,7 @@ func startRaft(tlsConfig TLSConfig) {
 					err = joinCluster(raftServer, machine, tlsConfig.Scheme)
 					err = joinCluster(raftServer, machine, tlsConfig.Scheme)
 					if err != nil {
 					if err != nil {
 						if err.Error() == errors[103] {
 						if err.Error() == errors[103] {
-							fmt.Println(err)
-							os.Exit(1)
+							fatal(err)
 						}
 						}
 						debugf("cannot join to cluster via machine %s %s", machine, err)
 						debugf("cannot join to cluster via machine %s %s", machine, err)
 					} else {
 					} else {
@@ -129,7 +127,7 @@ func startRaft(tlsConfig TLSConfig) {
 // Start to listen and response raft command
 // Start to listen and response raft command
 func startRaftTransport(info Info, scheme string, tlsConf tls.Config) {
 func startRaftTransport(info Info, scheme string, tlsConf tls.Config) {
 	u, _ := url.Parse(info.RaftURL)
 	u, _ := url.Parse(info.RaftURL)
-	fmt.Printf("raft server [%s] listening on %s\n", info.Name, u)
+	infof("raft server [%s:%s]", info.Name, u)
 
 
 	raftMux := http.NewServeMux()
 	raftMux := http.NewServeMux()
 
 

+ 4 - 0
util.go

@@ -105,6 +105,10 @@ func init() {
 	logger = log.New(os.Stdout, "[etcd] ", log.Lmicroseconds)
 	logger = log.New(os.Stdout, "[etcd] ", log.Lmicroseconds)
 }
 }
 
 
+func infof(msg string, v ...interface{}) {
+	logger.Printf("INFO "+msg+"\n", v...)
+}
+
 func debugf(msg string, v ...interface{}) {
 func debugf(msg string, v ...interface{}) {
 	if verbose {
 	if verbose {
 		logger.Printf("DEBUG "+msg+"\n", v...)
 		logger.Printf("DEBUG "+msg+"\n", v...)