Merge pull request #38 from xiangli-cmu/master

change log ouput format to Lmicroseconds
pull/820/head
Ben Johnson 2013-07-02 11:54:52 -07:00
commit 73aa2c52e3
2 changed files with 16 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package raft
import (
"log"
"os"
)
//------------------------------------------------------------------------------
@ -12,6 +13,11 @@ import (
// A flag stating if debug statements should be evaluated.
var Debug bool = false
var logger *log.Logger
func init() {
logger = log.New(os.Stdout, "", log.Lmicroseconds)
}
//------------------------------------------------------------------------------
//
@ -23,7 +29,7 @@ var Debug bool = false
// are handled in the manner of fmt.Print.
func debug(v ...interface{}) {
if Debug {
log.Print(v...)
logger.Print(v...)
}
}
@ -31,7 +37,8 @@ func debug(v ...interface{}) {
// are handled in the manner of fmt.Printf.
func debugf(format string, v ...interface{}) {
if Debug {
log.Printf(format, v...)
logger.Printf(format, v...)
}
}
@ -39,6 +46,6 @@ func debugf(format string, v ...interface{}) {
// are handled in the manner of debugln.
func debugln(v ...interface{}) {
if Debug {
log.Println(v...)
logger.Println(v...)
}
}

View File

@ -216,6 +216,11 @@ func (s *Server) LastCommandName() string {
return ""
}
// Get the state of the server for debugging
func (s *Server) GetState() string {
return fmt.Sprintf("State: %s, Term: %v, Index: %v ", s.state, s.currentTerm, s.CommittedIndex())
}
//--------------------------------------
// Membership
//--------------------------------------
@ -431,7 +436,7 @@ func (s *Server) commitCenter() {
if commitIndex > committedIndex {
debugln(indices)
debugln("[CommitCenter] Going to Commit ", commitIndex)
debugln(s.GetState(), "[CommitCenter] Going to Commit ", commitIndex)
s.log.SetCommitIndex(commitIndex)
debugln("[CommitCenter] Commit ", commitIndex)