From 7a19090e5d59ef648fa8f57f308ff4ecf4a17194 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 2 Jul 2013 11:42:14 -0700 Subject: [PATCH] change log ouput format to Lmicroseconds --- debug.go | 13 ++++++++++--- server.go | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/debug.go b/debug.go index dd255036cf9..07f13ae4f30 100644 --- a/debug.go +++ b/debug.go @@ -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...) } } diff --git a/server.go b/server.go index 3c9f9e737f2..1667b460b1c 100644 --- a/server.go +++ b/server.go @@ -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)