1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/common/log/log.go

54 lines
974 B
Go
Raw Normal View History

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