From 0232f522819f6d89a7b802e70a5b0398a52dd90a Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 5 Apr 2022 19:31:35 +0800 Subject: [PATCH] log --- cmd/open_im_api/main.go | 6 ++-- cmd/open_im_demo/main.go | 7 +++-- cmd/open_im_msg_gateway/main.go | 3 ++ cmd/open_im_msg_transfer/main.go | 3 ++ cmd/open_im_push/main.go | 3 ++ cmd/open_im_timer_task/main.go | 47 ++++++++++++++--------------- internal/api/third/minio_init.go | 17 ++++++----- internal/msg_gateway/gate/init.go | 5 ++- internal/msg_transfer/logic/init.go | 5 ++- internal/push/logic/init.go | 3 +- pkg/common/db/model.go | 12 ++++---- 11 files changed, 58 insertions(+), 53 deletions(-) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 7f1546022..8e76357f7 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -11,7 +11,6 @@ import ( apiThird "Open_IM/internal/api/third" "Open_IM/internal/api/user" "Open_IM/pkg/common/config" - "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/utils" "flag" @@ -21,10 +20,11 @@ import ( "github.com/gin-gonic/gin" //"syscall" + "Open_IM/pkg/common/constant" ) func main() { - + log.NewPrivateLog(constant.LogFileName) gin.SetMode(gin.ReleaseMode) f, _ := os.Create("../logs/api.log") gin.DefaultWriter = io.MultiWriter(f) @@ -136,7 +136,7 @@ func main() { officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs) } apiThird.MinioInit() - log.NewPrivateLog(constant.LogFileName) + log.Info("", "MinioInit fin") ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port") flag.Parse() r.Run(":" + strconv.Itoa(*ginPort)) diff --git a/cmd/open_im_demo/main.go b/cmd/open_im_demo/main.go index d7688d4dd..c35675e20 100644 --- a/cmd/open_im_demo/main.go +++ b/cmd/open_im_demo/main.go @@ -2,18 +2,19 @@ package main import ( "Open_IM/internal/demo/register" - "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/log" "Open_IM/pkg/utils" "flag" "io" "os" "strconv" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" "github.com/gin-gonic/gin" ) func main() { + log.NewPrivateLog(constant.LogFileName) gin.SetMode(gin.ReleaseMode) f, _ := os.Create("../logs/api.log") gin.DefaultWriter = io.MultiWriter(f) @@ -29,7 +30,7 @@ func main() { authRouterGroup.POST("/login", register.Login) authRouterGroup.POST("/reset_password", register.ResetPassword) } - log.NewPrivateLog(constant.LogFileName) + ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port") flag.Parse() r.Run(":" + strconv.Itoa(*ginPort)) diff --git a/cmd/open_im_msg_gateway/main.go b/cmd/open_im_msg_gateway/main.go index 196e6c005..5296c9bcf 100644 --- a/cmd/open_im_msg_gateway/main.go +++ b/cmd/open_im_msg_gateway/main.go @@ -2,11 +2,14 @@ package main import ( "Open_IM/internal/msg_gateway/gate" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" "flag" "sync" ) func main() { + log.NewPrivateLog(constant.LogFileName) rpcPort := flag.Int("rpc_port", 10400, "rpc listening port") wsPort := flag.Int("ws_port", 17778, "ws listening port") flag.Parse() diff --git a/cmd/open_im_msg_transfer/main.go b/cmd/open_im_msg_transfer/main.go index c5487de26..2a54ac1d8 100644 --- a/cmd/open_im_msg_transfer/main.go +++ b/cmd/open_im_msg_transfer/main.go @@ -2,12 +2,15 @@ package main import ( "Open_IM/internal/msg_transfer/logic" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" "sync" ) func main() { var wg sync.WaitGroup wg.Add(1) + log.NewPrivateLog(constant.LogFileName) logic.Init() logic.Run() wg.Wait() diff --git a/cmd/open_im_push/main.go b/cmd/open_im_push/main.go index 590793fbe..ba8dc65c1 100644 --- a/cmd/open_im_push/main.go +++ b/cmd/open_im_push/main.go @@ -2,6 +2,8 @@ package main import ( "Open_IM/internal/push/logic" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" "flag" "sync" ) @@ -11,6 +13,7 @@ func main() { flag.Parse() var wg sync.WaitGroup wg.Add(1) + log.NewPrivateLog(constant.LogFileName) logic.Init(*rpcPort) logic.Run() wg.Wait() diff --git a/cmd/open_im_timer_task/main.go b/cmd/open_im_timer_task/main.go index 37265e285..20d9a4d1c 100644 --- a/cmd/open_im_timer_task/main.go +++ b/cmd/open_im_timer_task/main.go @@ -2,10 +2,7 @@ package main import ( "Open_IM/pkg/common/constant" - commonDB "Open_IM/pkg/common/db" - "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" - "time" ) func main() { @@ -40,27 +37,27 @@ func main() { // time.Sleep(time.Duration(sleepTime) * time.Second) // } //} - for { - uidList, err := im_mysql_model.SelectAllUserID() - if err != nil { - //log.NewError("999999", err.Error()) - } else { - for _, v := range uidList { - minSeq, err := commonDB.DB.GetMinSeqFromMongo(v) - if err != nil { - //log.NewError("999999", "get user minSeq err", err.Error(), v) - continue - } else { - err := commonDB.DB.SetUserMinSeq(v, minSeq) - if err != nil { - //log.NewError("999999", "set user minSeq err", err.Error(), v) - } - } - time.Sleep(time.Duration(100) * time.Millisecond) - } - - } - - } + //for { + // uidList, err := im_mysql_model.SelectAllUserID() + // if err != nil { + // //log.NewError("999999", err.Error()) + // } else { + // for _, v := range uidList { + // minSeq, err := commonDB.DB.GetMinSeqFromMongo(v) + // if err != nil { + // //log.NewError("999999", "get user minSeq err", err.Error(), v) + // continue + // } else { + // err := commonDB.DB.SetUserMinSeq(v, minSeq) + // if err != nil { + // //log.NewError("999999", "set user minSeq err", err.Error(), v) + // } + // } + // time.Sleep(time.Duration(100) * time.Millisecond) + // } + // + // } + // + //} } diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index 564d19a1e..9a059cc0c 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -15,10 +15,11 @@ var ( ) func MinioInit() { - log.NewInfo("", utils.GetSelfFuncName()) + operationID := utils.OperationIDGenerator() + log.NewInfo(operationID, utils.GetSelfFuncName()) minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint) if err != nil { - log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error()) + log.NewError(operationID, utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error()) return } minioClient, err = minio.New(minioUrl.Host, &minio.Options{ @@ -26,7 +27,7 @@ func MinioInit() { Secure: false, }) if err != nil { - log.NewError("", utils.GetSelfFuncName(), "init minio client failed", err.Error()) + log.NewError(operationID, utils.GetSelfFuncName(), "init minio client failed", err.Error()) return } opt := minio.MakeBucketOptions{ @@ -35,15 +36,15 @@ func MinioInit() { } err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt) if err != nil { - log.NewInfo("", utils.GetSelfFuncName(), err.Error()) + log.NewInfo(operationID, utils.GetSelfFuncName(), err.Error()) exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket) if err == nil && exists { - log.NewInfo("", utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket) + log.NewInfo(operationID, utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket) } else { if err != nil { - log.NewError("", utils.GetSelfFuncName(), err.Error()) + log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) } - log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists") + log.NewError(operationID, utils.GetSelfFuncName(), "create bucket failed and bucket not exists") return } } @@ -53,5 +54,5 @@ func MinioInit() { // log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error()) // return //} - log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success") + log.NewInfo(operationID, utils.GetSelfFuncName(), "minio create and set policy success") } diff --git a/internal/msg_gateway/gate/init.go b/internal/msg_gateway/gate/init.go index e62338d14..8f2f2e35b 100644 --- a/internal/msg_gateway/gate/init.go +++ b/internal/msg_gateway/gate/init.go @@ -2,8 +2,7 @@ package gate import ( "Open_IM/pkg/common/config" - "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/log" + "Open_IM/pkg/statistics" "fmt" "github.com/go-playground/validator/v10" @@ -21,7 +20,7 @@ var ( func Init(rpcPort, wsPort int) { //log initialization - log.NewPrivateLog(constant.LogFileName) + rwLock = new(sync.RWMutex) validate = validator.New() statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 300) diff --git a/internal/msg_transfer/logic/init.go b/internal/msg_transfer/logic/init.go index e91f7dbe6..20326bbfc 100644 --- a/internal/msg_transfer/logic/init.go +++ b/internal/msg_transfer/logic/init.go @@ -2,9 +2,8 @@ package logic import ( "Open_IM/pkg/common/config" - "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/kafka" - "Open_IM/pkg/common/log" ) var ( @@ -14,7 +13,7 @@ var ( ) func Init() { - log.NewPrivateLog(constant.LogFileName) + persistentCH.Init() historyCH.Init() producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic) diff --git a/internal/push/logic/init.go b/internal/push/logic/init.go index a41f60a6a..d2d127091 100644 --- a/internal/push/logic/init.go +++ b/internal/push/logic/init.go @@ -10,7 +10,6 @@ import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/kafka" - "Open_IM/pkg/common/log" "Open_IM/pkg/statistics" "fmt" ) @@ -24,7 +23,7 @@ var ( ) func Init(rpcPort int) { - log.NewPrivateLog(constant.LogFileName) + rpcServer.Init(rpcPort) pushCh.Init() pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID} diff --git a/pkg/common/db/model.go b/pkg/common/db/model.go index 21dae1667..f9550e7b3 100644 --- a/pkg/common/db/model.go +++ b/pkg/common/db/model.go @@ -2,8 +2,7 @@ package db import ( "Open_IM/pkg/common/config" - "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/log" + //"Open_IM/pkg/common/log" "Open_IM/pkg/utils" "fmt" "go.mongodb.org/mongo-driver/mongo/options" @@ -34,7 +33,7 @@ func key(dbAddress, dbName string) string { } func init() { - log.NewPrivateLog(constant.LogFileName) + //log.NewPrivateLog(constant.LogFileName) //var mgoSession *mgo.Session var mongoClient *mongo.Client var err1 error @@ -54,15 +53,16 @@ func init() { mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) if err != nil { - log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri) + fmt.Println(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri) time.Sleep(time.Duration(30) * time.Second) mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) if err1 != nil { - log.NewError(" mongo.Connect retry failed, panic", err.Error(), uri) + fmt.Println(" mongo.Connect retry failed, panic", err.Error(), uri) panic(err1.Error()) } } - log.NewInfo("0", utils.GetSelfFuncName(), "mongo driver client init success") + fmt.Println("0", utils.GetSelfFuncName(), "mongo driver client init success") + DB.mongoClient = mongoClient //mgoDailInfo := &mgo.DialInfo{