Skip to content

Commit

Permalink
change log ouput format to Lmicroseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Jul 2, 2013
1 parent c9ce5b4 commit 7a19090
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package raft

import (
"log"
"os"
)

//------------------------------------------------------------------------------
Expand All @@ -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)
}

//------------------------------------------------------------------------------
//
Expand All @@ -23,22 +29,23 @@ var Debug bool = false
// are handled in the manner of fmt.Print.
func debug(v ...interface{}) {
if Debug {
log.Print(v...)
logger.Print(v...)
}
}

// Prints to the standard logger if debug mode is enabled. Arguments
// are handled in the manner of fmt.Printf.
func debugf(format string, v ...interface{}) {
if Debug {
log.Printf(format, v...)

logger.Printf(format, v...)
}
}

// Prints to the standard logger if debug mode is enabled. Arguments
// are handled in the manner of debugln.
func debugln(v ...interface{}) {
if Debug {
log.Println(v...)
logger.Println(v...)
}
}
7 changes: 6 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//--------------------------------------
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7a19090

Please sign in to comment.