influxdb/debug.go

117 lines
2.6 KiB
Go
Raw Normal View History

2013-06-25 20:11:48 +00:00
package raft
import (
"log"
"os"
2013-06-25 20:11:48 +00:00
)
//------------------------------------------------------------------------------
//
// Variables
//
//------------------------------------------------------------------------------
2013-07-07 20:21:04 +00:00
const (
Debug = 1
Trace = 2
)
2013-07-28 04:49:17 +00:00
var logLevel int = 0
var logger *log.Logger
func init() {
logger = log.New(os.Stdout, "[raft]", log.Lmicroseconds)
}
2013-06-25 20:11:48 +00:00
//------------------------------------------------------------------------------
//
// Functions
//
//------------------------------------------------------------------------------
2013-07-28 04:49:17 +00:00
func LogLevel() int {
return logLevel
}
func SetLogLevel(level int) {
2013-07-28 22:31:25 +00:00
logLevel = level
2013-07-28 04:49:17 +00:00
}
//--------------------------------------
// Warnings
//--------------------------------------
// Prints to the standard logger. Arguments are handled in the manner of
// fmt.Print.
func warn(v ...interface{}) {
logger.Print(v...)
}
// Prints to the standard logger. Arguments are handled in the manner of
// fmt.Printf.
func warnf(format string, v ...interface{}) {
logger.Printf(format, v...)
}
// Prints to the standard logger. Arguments are handled in the manner of
// fmt.Println.
func warnln(v ...interface{}) {
logger.Println(v...)
}
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-28 04:49:17 +00:00
if logLevel >= Debug {
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-28 04:49:17 +00:00
if logLevel >= Debug {
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 fmt.Println.
2013-06-25 20:11:48 +00:00
func debugln(v ...interface{}) {
2013-07-28 04:49:17 +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-28 04:49:17 +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-28 04:49:17 +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-28 04:49:17 +00:00
if logLevel >= Trace {
logger.Println(v...)
2013-06-25 20:11:48 +00:00
}
}