Commit 13557f1d by zhengqiuyun86

mysql加入连接配置

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