Commit 87b49891 by huangchengyi

1.0

parent 925873b3
......@@ -3,6 +3,7 @@ package boot
import (
"search_server/pkg/config"
"search_server/pkg/gredis"
"search_server/pkg/logger"
"search_server/pkg/mongo"
"search_server/pkg/mysql"
)
......@@ -23,9 +24,9 @@ func Boot(configPath string) (err error) {
panic(err)
return
}
//if err = logger.SetUp(); err != nil {
// panic(err)
// return
//}
if err = logger.SetUp(); err != nil {
panic(err)
return
}
return
}
......@@ -4,9 +4,6 @@ import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
log "github.com/sirupsen/logrus"
"os"
"search_server/pkg/config"
"search_server/pkg/gredis"
"search_server/pkg/message"
......@@ -61,10 +58,7 @@ func AnalyzeSearchError(ctx *gin.Context,code int, ip, errMsg, file, line, metho
redisCon := gredis.Conn("search_w")
defer redisCon.Close()
key := config.Get("SEARCH_API_LOG.SEARCH_API_ERROR_PRE").String() + unitSupplierLogCode[codeStr]
_, err := redis.Bool(redisCon.Do("INCR", key))
if err != nil {
logger.Error("%s", err)
}
redis.Bool(redisCon.Do("INCR", key))
}
return
}
......@@ -72,21 +66,9 @@ func AnalyzeSearchError(ctx *gin.Context,code int, ip, errMsg, file, line, metho
type LogFormatter struct{}
//格式详情
func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
msg := entry.Message + "\n"
return []byte(msg), nil
}
//func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
// msg := entry.Message + "\n"
// return []byte(msg), nil
//}
//写入到特定的文件夹给ELK使用的日志
func WriteSearchErrorLog(searchLog string) {
return;
// 设置日志格式为json格式
log.SetFormatter(new(LogFormatter))
path := "../logs/search/"
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
//生成当天的日志
filePath := path + time.Now().Format("20060102") + ".log"
file, _ := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
log.SetOutput(file)
log.Error(searchLog)
}
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/gin-gonic/gin"
"runtime"
"search_server/pkg/logger"
"strconv"
)
......@@ -87,5 +88,5 @@ func SearchApiLogger(ctx *gin.Context,code int, msg string) {
lineNo := strconv.Itoa(line)
searchLog := AnalyzeSearchError(ctx,code, ctx.ClientIP(), errMsg, file, lineNo, f.Name())
searchLogByte, _ := json.Marshal(searchLog)
WriteSearchErrorLog(string(searchLogByte))
logger.Log(string(searchLogByte),"elk")
}
......@@ -7,7 +7,7 @@ import (
func SetUp() (err error) {
logConfig := make(map[string]string)
logConfig["log_path"] = "logs"
logConfig["log_chan_size"] = "5000"
logConfig["log_chan_size"] = "5"
err = logger.InitLogger("file", logConfig)
if err != nil {
return err
......
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 sign in to comment