feat: 完善数据库信息保存以及项目、redis相关操作

This commit is contained in:
meilin.huang
2021-07-28 18:03:19 +08:00
parent 3ebc3ee14d
commit bda3920c1e
153 changed files with 5527 additions and 1017 deletions

View File

@@ -2,6 +2,9 @@ package logger
import (
"fmt"
"mayfly-go/base/config"
"mayfly-go/base/global"
"os"
"strings"
"time"
@@ -11,12 +14,38 @@ import (
var Log = logrus.New()
func init() {
// customFormatter := new(logrus.TextFormatter)
// customFormatter.TimestampFormat = "2006-01-02 15:04:05.000"
// customFormatter.FullTimestamp = true
Log.SetFormatter(new(LogFormatter))
Log.SetReportCaller(true)
Log.SetLevel(logrus.DebugLevel)
logConf := config.Conf.Log
// 如果不存在日志配置信息则默认debug级别
if logConf == nil {
Log.SetLevel(logrus.DebugLevel)
return
}
// 根据配置文件设置日志级别
if level := logConf.Level; level != "" {
l, err := logrus.ParseLevel(level)
if err != nil {
panic(fmt.Sprintf("日志级别不存在: %s", level))
}
Log.SetLevel(l)
} else {
Log.SetLevel(logrus.DebugLevel)
}
if logFile := logConf.File; logFile != nil {
//写入文件
file, err := os.OpenFile(logFile.GetFilename(), os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModeAppend|0666)
if err != nil {
panic(fmt.Sprintf("创建日志文件失败: %s", err.Error()))
}
Log.Out = file
}
global.Log = Log
}
type LogFormatter struct{}