Commit 13557f1d by zhengqiuyun86

mysql加入连接配置

parent 1ebe242b
......@@ -13,6 +13,7 @@ import (
const (
LevelDebug = "Debug"
LevelInfo = "Info"
LevelWarn = "Warn"
LevelError = "Error"
)
......@@ -41,7 +42,7 @@ func Debug(msg string) {
}
if ok {
_, file, line, _ := runtime.Caller(1)
print("Debug", msg, file, line)
print(LevelDebug, msg, file, line)
}
}
......@@ -49,15 +50,28 @@ func Info(msg string) {
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
case strings.ToLower(LevelInfo):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print(LevelInfo, msg, file, line)
}
}
func Warn(msg string) {
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
case strings.ToLower(LevelInfo):
case strings.ToLower(LevelWarn):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print("Info", msg, file, line)
print(LevelWarn, msg, file, line)
}
}
......@@ -65,23 +79,18 @@ func Error(msg string) {
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
ok = true
break
case strings.ToLower(LevelInfo):
ok = true
break
case strings.ToLower(LevelWarn):
case strings.ToLower(LevelError):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print("Error", msg, file, line)
print(LevelError, msg, file, line)
}
}
// Colors
const (
reset = "\033[0m"
......@@ -101,12 +110,18 @@ const (
func print(tag, msg string, file string, line int) {
str := "%s %s [%d] %s %d %s"
if conf.LogColorful {
if tag == "Error" {
str = "%s %s [%d] %s %d " + red + "%s" + reset
} else if tag == "Info" {
str = "%s %s [%d] %s %d " + yellow + "%s" + reset
} else {
switch tag {
case strings.ToLower(LevelDebug):
str = "%s %s [%d] %s %d " + green + "%s" + reset
break
case strings.ToLower(LevelInfo):
break
case strings.ToLower(LevelWarn):
str = "%s %s [%d] %s %d " + yellow + "%s" + reset
break
case strings.ToLower(LevelError):
str = "%s %s [%d] %s %d " + red + "%s" + reset
break
}
}
file = file[strings.LastIndex(file, "/")+1:]
......
......@@ -70,7 +70,7 @@ func Get(key string) []byte {
r := getDb().Get(key)
rByte, err := r.Bytes()
if err != nil {
log.Error(fmt.Sprintf("获取缓存错误:%s", err.Error()))
log.Warn(fmt.Sprintf("获取缓存错误:%s", err.Error()))
}
return rByte
}
......@@ -85,7 +85,7 @@ func Expire(k string, t int64) bool {
if b.Val() {
log.Debug(fmt.Sprintf("设置缓存过期成功:%s %d", k, t))
} else {
log.Debug(fmt.Sprintf("设置缓存过期失败:%s %d", k, t))
log.Warn(fmt.Sprintf("设置缓存过期失败:%s %d", k, t))
}
return b.Val()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment