uquic/utils/log.go
Lucas Clemente 09fb894fb2 add custom logger
fixes #45
2016-05-04 13:20:24 +02:00

45 lines
897 B
Go

package utils
import "fmt"
// LogLevel of quic-go
type LogLevel uint8
const (
// LogLevelDebug enables debug logs (e.g. packet contents)
LogLevelDebug LogLevel = iota
// LogLevelInfo enables info logs (e.g. packets)
LogLevelInfo
// LogLevelError enables err logs
LogLevelError
// LogLevelNothing disables
LogLevelNothing
)
var logLevel = LogLevelNothing
// SetLogLevel sets the log level
func SetLogLevel(level LogLevel) {
logLevel = level
}
// Debugf logs something
func Debugf(format string, args ...interface{}) {
if logLevel == LogLevelDebug {
fmt.Printf(format+"\n", args...)
}
}
// Infof logs something
func Infof(format string, args ...interface{}) {
if logLevel <= LogLevelInfo {
fmt.Printf(format+"\n", args...)
}
}
// Errorf logs something
func Errorf(format string, args ...interface{}) {
if logLevel <= LogLevelError {
fmt.Printf(format+"\n", args...)
}
}