2015-09-11 11:27:36 -04:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DebugLevel = LogLevel(0)
|
|
|
|
InfoLevel = LogLevel(1)
|
|
|
|
WarningLevel = LogLevel(2)
|
|
|
|
ErrorLevel = LogLevel(3)
|
|
|
|
)
|
|
|
|
|
|
|
|
var logLevel = WarningLevel
|
|
|
|
|
|
|
|
type LogLevel int
|
|
|
|
|
|
|
|
func SetLogLevel(level LogLevel) {
|
|
|
|
logLevel = level
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeLog(data string, level LogLevel) {
|
|
|
|
if level < logLevel {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Print(data)
|
|
|
|
}
|
|
|
|
|
2015-09-12 05:51:42 -04:00
|
|
|
func Debug(format string, v ...interface{}) {
|
|
|
|
data := fmt.Sprintf(format, v)
|
|
|
|
writeLog("[Debug]"+data, DebugLevel)
|
|
|
|
}
|
|
|
|
|
2015-09-11 11:27:36 -04:00
|
|
|
func Info(format string, v ...interface{}) {
|
|
|
|
data := fmt.Sprintf(format, v)
|
|
|
|
writeLog("[Info]"+data, InfoLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Warning(format string, v ...interface{}) {
|
|
|
|
data := fmt.Sprintf(format, v)
|
|
|
|
writeLog("[Warning]"+data, WarningLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Error(format string, v ...interface{}) error {
|
|
|
|
data := fmt.Sprintf(format, v)
|
|
|
|
writeLog("[Error]"+data, ErrorLevel)
|
|
|
|
return errors.New(data)
|
|
|
|
}
|