2013-06-25 20:11:48 +00:00
|
|
|
package raft
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2013-07-02 18:42:14 +00:00
|
|
|
"os"
|
2013-06-25 20:11:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Variables
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-07-07 20:21:04 +00:00
|
|
|
const (
|
|
|
|
Debug = 1
|
|
|
|
Trace = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
var LogLevel int = 0
|
2013-07-02 18:42:14 +00:00
|
|
|
var logger *log.Logger
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
logger = log.New(os.Stdout, "", log.Lmicroseconds)
|
|
|
|
}
|
2013-06-25 20:11:48 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Functions
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-07-06 19:41:42 +00:00
|
|
|
//--------------------------------------
|
|
|
|
// Basic debugging
|
|
|
|
//--------------------------------------
|
|
|
|
|
2013-06-25 20:11:48 +00:00
|
|
|
// Prints to the standard logger if debug mode is enabled. Arguments
|
|
|
|
// are handled in the manner of fmt.Print.
|
|
|
|
func debug(v ...interface{}) {
|
2013-07-07 20:21:04 +00:00
|
|
|
if LogLevel >= Debug {
|
2013-07-02 18:42:14 +00:00
|
|
|
logger.Print(v...)
|
2013-06-25 20:11:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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{}) {
|
2013-07-07 20:21:04 +00:00
|
|
|
if LogLevel >= Debug {
|
2013-07-02 18:42:14 +00:00
|
|
|
logger.Printf(format, v...)
|
2013-06-25 20:11:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints to the standard logger if debug mode is enabled. Arguments
|
|
|
|
// are handled in the manner of debugln.
|
|
|
|
func debugln(v ...interface{}) {
|
2013-07-07 20:21:04 +00:00
|
|
|
if LogLevel >= Debug {
|
2013-07-06 19:41:42 +00:00
|
|
|
logger.Println(v...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------
|
|
|
|
// Trace-level debugging
|
|
|
|
//--------------------------------------
|
|
|
|
|
|
|
|
// Prints to the standard logger if trace debugging is enabled. Arguments
|
|
|
|
// are handled in the manner of fmt.Print.
|
|
|
|
func trace(v ...interface{}) {
|
2013-07-07 20:21:04 +00:00
|
|
|
if LogLevel >= Trace {
|
2013-07-06 19:41:42 +00:00
|
|
|
logger.Print(v...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints to the standard logger if trace debugging is enabled. Arguments
|
|
|
|
// are handled in the manner of fmt.Printf.
|
|
|
|
func tracef(format string, v ...interface{}) {
|
2013-07-07 20:21:04 +00:00
|
|
|
if LogLevel >= Trace {
|
2013-07-06 19:41:42 +00:00
|
|
|
logger.Printf(format, v...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints to the standard logger if trace debugging is enabled. Arguments
|
|
|
|
// are handled in the manner of debugln.
|
|
|
|
func traceln(v ...interface{}) {
|
2013-07-07 20:21:04 +00:00
|
|
|
if LogLevel >= Trace {
|
2013-07-02 18:42:14 +00:00
|
|
|
logger.Println(v...)
|
2013-06-25 20:11:48 +00:00
|
|
|
}
|
|
|
|
}
|