Skip to content

Commit

Permalink
Merge pull request #4 from xiangli-cmu/master
Browse files Browse the repository at this point in the history
add [etcd] as the prefix of the logging info
  • Loading branch information
xiang90 committed Jul 9, 2013
2 parents c114ed4 + 2589a76 commit 0d10a1e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import (
"github.com/coreos/etcd/web"
"io"
"io/ioutil"
"log"
"net/http"
"os"
)

//--------------------------------------
// Web Helper
//--------------------------------------
var storeMsg chan string

// Help to send msg from stroe to webHub
func webHelper() {
storeMsg = make(chan string)
for {
// transfere the new msg to webHub
web.Hub().Send(<-storeMsg)
}
}
Expand All @@ -28,7 +32,7 @@ func webHelper() {
func decodeJsonRequest(req *http.Request, data interface{}) error {
decoder := json.NewDecoder(req.Body)
if err := decoder.Decode(&data); err != nil && err != io.EOF {
logger.Println("Malformed json request: %v", err)
warn("Malformed json request: %v", err)
return fmt.Errorf("Malformed json request: %v", err)
}
return nil
Expand Down Expand Up @@ -79,6 +83,12 @@ func leaderClient() string {
// Log
//--------------------------------------

var logger *log.Logger

func init() {
logger = log.New(os.Stdout, "[etcd] ", log.Lmicroseconds)
}

func debug(msg string, v ...interface{}) {
if verbose {
logger.Printf("DEBUG "+msg+"\n", v...)
Expand All @@ -90,7 +100,7 @@ func info(msg string, v ...interface{}) {
}

func warn(msg string, v ...interface{}) {
logger.Printf("Alpaca Server: WARN "+msg+"\n", v...)
logger.Printf("WARN "+msg+"\n", v...)
}

func fatal(msg string, v ...interface{}) {
Expand Down

0 comments on commit 0d10a1e

Please sign in to comment.