1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-16 17:39:08 -04:00

Move log into common

This commit is contained in:
V2Ray
2015-09-20 00:50:21 +02:00
parent d03cac9670
commit a887fd01b8
15 changed files with 20 additions and 20 deletions

View File

@@ -4,7 +4,7 @@ import (
"crypto/cipher"
"io"
"github.com/v2ray/v2ray-core/log"
"github.com/v2ray/v2ray-core/common/log"
)
// CryptionReader is a general purpose reader that applies

53
common/log/log.go Normal file
View File

@@ -0,0 +1,53 @@
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)
}