Przeglądaj źródła

api增加日志配置

renjiaojiao 2 lat temu
rodzic
commit
ee706ea805
2 zmienionych plików z 26 dodań i 0 usunięć
  1. 6 0
      api/etc/logs.yaml
  2. 20 0
      api/message.go

+ 6 - 0
api/etc/logs.yaml

@@ -0,0 +1,6 @@
+Mode: file
+Path: ./logs
+Level:
+  - info
+  - error
+KeepDays: 10

+ 20 - 0
api/message.go

@@ -1,8 +1,10 @@
 package main
 
 import (
+	"app.yhyue.com/moapp/MessageCenter/entity"
 	"flag"
 	"fmt"
+	"github.com/tal-tech/go-zero/core/logx"
 
 	"app.yhyue.com/moapp/MessageCenter/api/internal/config"
 	"app.yhyue.com/moapp/MessageCenter/api/internal/handler"
@@ -13,6 +15,8 @@ import (
 )
 
 var configFile = flag.String("f", "etc/message-api.yaml", "the config file")
+var logFile = flag.String("lf", "etc/logs.yaml", "the logs file")
+var logc entity.Logc
 
 func main() {
 	flag.Parse()
@@ -29,3 +33,19 @@ func main() {
 	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
 	server.Start()
 }
+
+func init() {
+	//初始化日志信息
+	conf.MustLoad(*logFile, &logc)
+	if len(logc.Level) > 0 {
+		for _, v := range logc.Level {
+			logx.MustSetup(logx.LogConf{
+				Mode:     logc.Mode,
+				Path:     logc.Path,
+				Level:    v,
+				KeepDays: logc.KeepDays,
+			})
+			logx.Info(v, "--日志记录")
+		}
+	}
+}