1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 17:27:23 -05:00
v2fly/log/log.go
2015-09-12 20:36:21 +02:00

54 lines
972 B
Go

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(level LogLevel, prefix, format string, v ...interface{}) string {
if level < logLevel {
return ""
}
var data string
if v == nil || len(v) == 0 {
data = format
} else {
data = fmt.Sprintf(format, v...)
}
log.Print(prefix + data)
return data
}
func Debug(format string, v ...interface{}) {
writeLog(DebugLevel, "[Debug]", format, v...)
}
func Info(format string, v ...interface{}) {
writeLog(InfoLevel, "[Info]", format, v...)
}
func Warning(format string, v ...interface{}) {
writeLog(WarningLevel, "[Warning]", format, v...)
}
func Error(format string, v ...interface{}) error {
data := writeLog(ErrorLevel, "[Error]", format, v...)
return errors.New(data)
}