From ecd2f0e2bfacc83d667bc8ce23cd9a4664d325b4 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 31 Mar 2022 11:15:06 +0800 Subject: [PATCH] Merge log files --- cmd/Open-IM-SDK-Core | 2 +- cmd/open_im_api/main.go | 3 ++- cmd/open_im_demo/main.go | 3 ++- cmd/open_im_timer_task/main.go | 3 ++- internal/msg_transfer/logic/init.go | 3 ++- internal/push/logic/init.go | 2 +- internal/rpc/admin_cms/admin_cms.go | 8 ++++---- internal/rpc/auth/auth.go | 2 +- internal/rpc/friend/firend.go | 2 +- internal/rpc/group/group.go | 2 +- internal/rpc/message_cms/message_cms.go | 20 ++++++++++---------- internal/rpc/msg/rpcChat.go | 3 ++- internal/rpc/office/office.go | 2 +- internal/rpc/statistics/statistics.go | 8 ++++---- internal/rpc/user/user.go | 2 +- pkg/common/constant/constant.go | 2 ++ pkg/common/log/logrus.go | 8 ++++---- 17 files changed, 41 insertions(+), 34 deletions(-) diff --git a/cmd/Open-IM-SDK-Core b/cmd/Open-IM-SDK-Core index 884d0d0b2..7b66c0ab7 160000 --- a/cmd/Open-IM-SDK-Core +++ b/cmd/Open-IM-SDK-Core @@ -1 +1 @@ -Subproject commit 884d0d0b2712f269db3f7f7fc7309759854dcb03 +Subproject commit 7b66c0ab78be494ce2cfe23de37543dd11c2d354 diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 2f93c97e8..10626a8ef 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -10,6 +10,7 @@ import ( "Open_IM/internal/api/office" apiThird "Open_IM/internal/api/third" "Open_IM/internal/api/user" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/utils" "flag" @@ -125,7 +126,7 @@ func main() { officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs) } apiThird.MinioInit() - log.NewPrivateLog("api") + log.NewPrivateLog(constant.LogFileName) 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 430b0faaf..58f5826db 100644 --- a/cmd/open_im_demo/main.go +++ b/cmd/open_im_demo/main.go @@ -2,6 +2,7 @@ package main import ( "Open_IM/internal/demo/register" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/utils" "flag" @@ -23,7 +24,7 @@ func main() { authRouterGroup.POST("/login", register.Login) authRouterGroup.POST("/reset_password", register.ResetPassword) } - log.NewPrivateLog("demo") + 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_timer_task/main.go b/cmd/open_im_timer_task/main.go index 954c41ae6..37265e285 100644 --- a/cmd/open_im_timer_task/main.go +++ b/cmd/open_im_timer_task/main.go @@ -1,6 +1,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" @@ -8,7 +9,7 @@ import ( ) func main() { - log.NewPrivateLog("timer") + log.NewPrivateLog(constant.LogFileName) //for { // fmt.Println("start delete mongodb expired record") // timeUnixBegin := time.Now().Unix() diff --git a/internal/msg_transfer/logic/init.go b/internal/msg_transfer/logic/init.go index cce434d99..e91f7dbe6 100644 --- a/internal/msg_transfer/logic/init.go +++ b/internal/msg_transfer/logic/init.go @@ -2,6 +2,7 @@ package logic import ( "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/kafka" "Open_IM/pkg/common/log" ) @@ -13,7 +14,7 @@ var ( ) func Init() { - log.NewPrivateLog(config.Config.ModuleName.MsgTransferName) + 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 6f6f061b8..a41f60a6a 100644 --- a/internal/push/logic/init.go +++ b/internal/push/logic/init.go @@ -24,7 +24,7 @@ var ( ) func Init(rpcPort int) { - log.NewPrivateLog(config.Config.ModuleName.PushName) + log.NewPrivateLog(constant.LogFileName) rpcServer.Init(rpcPort) pushCh.Init() pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID} diff --git a/internal/rpc/admin_cms/admin_cms.go b/internal/rpc/admin_cms/admin_cms.go index 8d36f3724..156748bbc 100644 --- a/internal/rpc/admin_cms/admin_cms.go +++ b/internal/rpc/admin_cms/admin_cms.go @@ -24,7 +24,7 @@ type adminCMSServer struct { } func NewAdminCMSServer(port int) *adminCMSServer { - log.NewPrivateLog("AdminCMS") + log.NewPrivateLog(constant.LogFileName) return &adminCMSServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName, @@ -66,12 +66,12 @@ func (s *adminCMSServer) Run() { func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbAdminCMS.AdminLoginResp{} - for i, adminID := range config.Config.Manager.AppManagerUid{ + for i, adminID := range config.Config.Manager.AppManagerUid { if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret { token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error()) return resp, openIMHttp.WrapError(constant.ErrTokenUnknown) } resp.Token = token @@ -84,4 +84,4 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi return resp, openIMHttp.WrapError(constant.ErrTokenMalformed) } return resp, nil -} \ No newline at end of file +} diff --git a/internal/rpc/auth/auth.go b/internal/rpc/auth/auth.go index ed6ec4404..1aa0ec50b 100644 --- a/internal/rpc/auth/auth.go +++ b/internal/rpc/auth/auth.go @@ -63,7 +63,7 @@ type rpcAuth struct { } func NewRpcAuthServer(port int) *rpcAuth { - log.NewPrivateLog("auth") + log.NewPrivateLog(constant.LogFileName) return &rpcAuth{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName, diff --git a/internal/rpc/friend/firend.go b/internal/rpc/friend/firend.go index d79f2af33..b570b8106 100644 --- a/internal/rpc/friend/firend.go +++ b/internal/rpc/friend/firend.go @@ -29,7 +29,7 @@ type friendServer struct { } func NewFriendServer(port int) *friendServer { - log.NewPrivateLog("friend") + log.NewPrivateLog(constant.LogFileName) return &friendServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName, diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 50baff39e..edece9829 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -31,7 +31,7 @@ type groupServer struct { } func NewGroupServer(port int) *groupServer { - log.NewPrivateLog("group") + log.NewPrivateLog(constant.LogFileName) return &groupServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName, diff --git a/internal/rpc/message_cms/message_cms.go b/internal/rpc/message_cms/message_cms.go index d71394668..7f27e007a 100644 --- a/internal/rpc/message_cms/message_cms.go +++ b/internal/rpc/message_cms/message_cms.go @@ -31,7 +31,7 @@ type messageCMSServer struct { } func NewMessageCMSServer(port int) *messageCMSServer { - log.NewPrivateLog("MessageCMS") + log.NewPrivateLog(constant.LogFileName) return &messageCMSServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName, @@ -84,8 +84,8 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error()) } chatLog := db.ChatLog{ - Content: req.Content, - SendTime: time, + Content: req.Content, + SendTime: time, ContentType: req.ContentType, SessionType: req.SessionType, } @@ -101,20 +101,20 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error()) } - chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber) + chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error()) return resp, errors.WrapError(constant.ErrDB) } for _, chatLog := range chatLogs { pbChatLog := &pbMessageCMS.ChatLogs{ - SessionType: chatLog.SessionType, - ContentType: chatLog.ContentType, - SearchContent: req.Content, - WholeContent: chatLog.Content, - Date: chatLog.CreateTime.String(), + SessionType: chatLog.SessionType, + ContentType: chatLog.ContentType, + SearchContent: req.Content, + WholeContent: chatLog.Content, + Date: chatLog.CreateTime.String(), SenderNickName: chatLog.SenderNickname, - SenderId: chatLog.SendID, + SenderId: chatLog.SendID, } if chatLog.SenderNickname == "" { sendUser, err := imdb.GetUserByUserID(chatLog.SendID) diff --git a/internal/rpc/msg/rpcChat.go b/internal/rpc/msg/rpcChat.go index 43113ae51..c0f723a91 100644 --- a/internal/rpc/msg/rpcChat.go +++ b/internal/rpc/msg/rpcChat.go @@ -2,6 +2,7 @@ package msg import ( "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/kafka" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" @@ -22,7 +23,7 @@ type rpcChat struct { } func NewRpcChatServer(port int) *rpcChat { - log.NewPrivateLog("msg") + log.NewPrivateLog(constant.LogFileName) rc := rpcChat{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName, diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index e96475773..914990673 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -26,7 +26,7 @@ type officeServer struct { } func NewOfficeServer(port int) *officeServer { - log.NewPrivateLog("office") + log.NewPrivateLog(constant.LogFileName) return &officeServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImOfficeName, diff --git a/internal/rpc/statistics/statistics.go b/internal/rpc/statistics/statistics.go index e8b1383f9..cda164332 100644 --- a/internal/rpc/statistics/statistics.go +++ b/internal/rpc/statistics/statistics.go @@ -19,10 +19,10 @@ import ( //open_im_sdk "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" //"context" + errors "Open_IM/pkg/common/http" "net" "strconv" "strings" - errors "Open_IM/pkg/common/http" "google.golang.org/grpc" ) @@ -35,7 +35,7 @@ type statisticsServer struct { } func NewStatisticsServer(port int) *statisticsServer { - log.NewPrivateLog("Statistics") + log.NewPrivateLog(constant.LogFileName) return &statisticsServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName, @@ -164,7 +164,7 @@ func GetRangeDate(from, to time.Time) [][2]time.Time { } // month case !isInOneMonth(from, to): - if to.Sub(from) < time.Hour * 24 * 30 { + if to.Sub(from) < time.Hour*24*30 { for i := 0; ; i++ { fromTime := from.Add(time.Hour * 24 * time.Duration(i)) toTime := from.Add(time.Hour * 24 * time.Duration(i+1)) @@ -251,7 +251,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error()) } resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{ - Date: v[0].String(), + Date: v[0].String(), Num: num, } }(wg, i, v) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index cbeb9240b..299fca101 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -32,7 +32,7 @@ type userServer struct { } func NewUserServer(port int) *userServer { - log.NewPrivateLog("user") + log.NewPrivateLog(constant.LogFileName) return &userServer{ rpcPort: port, rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName, diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index a38076e7b..0fdf9dbec 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -230,3 +230,5 @@ func GroupIsBanPrivateChat(status int32) bool { } const BigVersion = "v3" + +const LogFileName = "OpenIM.log" diff --git a/pkg/common/log/logrus.go b/pkg/common/log/logrus.go index a5e0ae7dd..caf4c9126 100644 --- a/pkg/common/log/logrus.go +++ b/pkg/common/log/logrus.go @@ -63,10 +63,10 @@ func loggerInit(moduleName string) *Logger { } func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook { lfsHook := lfshook.NewHook(lfshook.WriterMap{ - logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "debug", moduleName), - logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "info", moduleName), - logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "warn", moduleName), - logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "error", moduleName), + logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), }, &nested.Formatter{ TimestampFormat: "2006-01-02 15:04:05.000", HideKeys: false,