mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 10:05:58 +08:00
log
This commit is contained in:
@@ -205,21 +205,21 @@ const (
|
||||
VerificationCodeForResetSuffix = "_forReset"
|
||||
|
||||
//callbackCommand
|
||||
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand"
|
||||
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand"
|
||||
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand"
|
||||
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
||||
CallbackMsgModifyCommand = "callbackMsgModifyCommand"
|
||||
CallbackUserOnlineCommand = "callbackUserOnlineCommand"
|
||||
CallbackUserOfflineCommand = "callbackUserOfflineCommand"
|
||||
CallbackUserKickOffCommand = "callbackUserKickOffCommand"
|
||||
CallbackOfflinePushCommand = "callbackOfflinePushCommand"
|
||||
CallbackOnlinePushCommand = "callbackOnlinePushCommand"
|
||||
CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand"
|
||||
CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand"
|
||||
CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand"
|
||||
CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand"
|
||||
CallbackBeforeSetGroupMemberInfoCommand = "CallbackBeforeSetGroupMemberInfoCommand"
|
||||
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand"
|
||||
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand"
|
||||
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand"
|
||||
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
||||
CallbackMsgModifyCommand = "callbackMsgModifyCommand"
|
||||
CallbackUserOnlineCommand = "callbackUserOnlineCommand"
|
||||
CallbackUserOfflineCommand = "callbackUserOfflineCommand"
|
||||
CallbackUserKickOffCommand = "callbackUserKickOffCommand"
|
||||
CallbackOfflinePushCommand = "callbackOfflinePushCommand"
|
||||
CallbackOnlinePushCommand = "callbackOnlinePushCommand"
|
||||
CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand"
|
||||
CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand"
|
||||
CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand"
|
||||
CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand"
|
||||
CallbackBeforeSetGroupMemberInfoCommand = "CallbackBeforeSetGroupMemberInfoCommand"
|
||||
CallbackBeforeSetMessageReactionExtensionCommand = "callbackBeforeSetMessageReactionExtensionCommand"
|
||||
CallbackBeforeDeleteMessageReactionExtensionsCommand = "callbackBeforeDeleteMessageReactionExtensionsCommand"
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ type Friend struct {
|
||||
|
||||
func (*Friend) Create(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(FriendDB.Create(&friends).Error, "")
|
||||
return err
|
||||
@@ -30,7 +30,7 @@ func (*Friend) Create(ctx context.Context, friends []*Friend) (err error) {
|
||||
|
||||
func (*Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
}()
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ? and friend_user_id in (?)", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
return err
|
||||
@@ -38,21 +38,21 @@ func (*Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs []s
|
||||
|
||||
func (*Friend) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(FriendDB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*Friend) Update(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(FriendDB.Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (*Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, err
|
||||
@@ -60,7 +60,7 @@ func (*Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend,
|
||||
|
||||
func (*Friend) Take(ctx context.Context, ownerUserID, friendUserID string) (group *Group, err error) {
|
||||
group = &Group{}
|
||||
defer trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "group", *group)
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "group", *group)
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(group).Error, "")
|
||||
return group, err
|
||||
}
|
||||
|
||||
@@ -29,33 +29,33 @@ type GroupMember struct {
|
||||
|
||||
func (g *GroupMember) Create(ctx context.Context, groupMemberList []*GroupMember) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMemberList", groupMemberList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMemberList", groupMemberList)
|
||||
}()
|
||||
return utils.Wrap(GroupMemberDB.Create(&groupMemberList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) Delete(ctx context.Context, groupMembers []*GroupMember) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers)
|
||||
}()
|
||||
return utils.Wrap(GroupMemberDB.Delete(groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(GroupMemberDB.Model(&GroupMember{}).Where("group_id = ? and user_id = ?", groupID, userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) Update(ctx context.Context, groupMembers []*GroupMember) (err error) {
|
||||
defer func() { trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers) }()
|
||||
defer func() { trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers) }()
|
||||
return utils.Wrap(GroupMemberDB.Updates(&groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) Find(ctx context.Context, groupMembers []*GroupMember) (groupList []*GroupMember, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers, "groupList", groupList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers, "groupList", groupList)
|
||||
}()
|
||||
var where [][]interface{}
|
||||
for _, groupMember := range groupMembers {
|
||||
@@ -67,7 +67,7 @@ func (g *GroupMember) Find(ctx context.Context, groupMembers []*GroupMember) (gr
|
||||
|
||||
func (g *GroupMember) Take(ctx context.Context, groupID string, userID string) (groupMember *GroupMember, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
}()
|
||||
groupMember = &GroupMember{}
|
||||
return groupMember, utils.Wrap(GroupMemberDB.Where("group_id = ? and user_id = ?", groupID, userID).Take(groupMember).Error, "")
|
||||
@@ -75,7 +75,7 @@ func (g *GroupMember) Take(ctx context.Context, groupID string, userID string) (
|
||||
|
||||
func (g *GroupMember) TakeOwnerInfo(ctx context.Context, groupID string) (groupMember *GroupMember, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMember", *groupMember)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMember", *groupMember)
|
||||
}()
|
||||
groupMember = &GroupMember{}
|
||||
err = GroupMemberDB.Where("group_id = ? and role_level = ?", groupID, constant.GroupOwner).Take(groupMember).Error
|
||||
|
||||
@@ -30,7 +30,7 @@ type Group struct {
|
||||
|
||||
func (*Group) Create(ctx context.Context, groups []*Group) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
}()
|
||||
err = utils.Wrap(GroupDB.Create(&groups).Error, "")
|
||||
return err
|
||||
@@ -38,28 +38,28 @@ func (*Group) Create(ctx context.Context, groups []*Group) (err error) {
|
||||
|
||||
func (*Group) Delete(ctx context.Context, groupIDs []string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
}()
|
||||
return utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Delete(&Group{}).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(GroupDB.Where("group_id = ?", groupID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) Update(ctx context.Context, groups []*Group) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
}()
|
||||
return utils.Wrap(GroupDB.Updates(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) Find(ctx context.Context, groupIDs []string) (groupList []*Group, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupIDList", groupIDs, "groupList", groupList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDList", groupIDs, "groupList", groupList)
|
||||
}()
|
||||
err = utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Find(&groupList).Error, "")
|
||||
return groupList, err
|
||||
@@ -68,7 +68,7 @@ func (*Group) Find(ctx context.Context, groupIDs []string) (groupList []*Group,
|
||||
func (*Group) Take(ctx context.Context, groupID string) (group *Group, err error) {
|
||||
group = &Group{}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
}()
|
||||
err = utils.Wrap(GroupDB.Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
return group, err
|
||||
|
||||
@@ -27,35 +27,35 @@ type GroupRequest struct {
|
||||
|
||||
func (*GroupRequest) Create(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Create(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Delete(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Delete(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Where("group_id = ? and user_id = ? ", groupID, userID).Updates(args).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Update(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Updates(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Find(ctx context.Context, groupRequests []*GroupRequest) (resultGroupRequests []*GroupRequest, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests, "resultGroupRequests", resultGroupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests, "resultGroupRequests", resultGroupRequests)
|
||||
}()
|
||||
var where [][]interface{}
|
||||
for _, groupMember := range groupRequests {
|
||||
@@ -67,7 +67,7 @@ func (*GroupRequest) Find(ctx context.Context, groupRequests []*GroupRequest) (r
|
||||
func (*GroupRequest) Take(ctx context.Context, groupID string, userID string) (groupRequest *GroupRequest, err error) {
|
||||
groupRequest = &GroupRequest{}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
|
||||
}()
|
||||
return groupRequest, utils.Wrap(GroupRequestDB.Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ type Black struct {
|
||||
}
|
||||
|
||||
func InsertInToUserBlackList(ctx context.Context, black Black) (err error) {
|
||||
defer trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "black", black)
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "black", black)
|
||||
black.CreateTime = time.Now()
|
||||
err = BlackDB.Create(black).Error
|
||||
return err
|
||||
|
||||
@@ -83,7 +83,7 @@ func GetFriendIDListFromCache(ctx context.Context, userID string) (friendIDList
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "friendIDList", friendIDList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "friendIDList", friendIDList)
|
||||
}()
|
||||
friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second*30*60, getFriendIDList)
|
||||
if err != nil {
|
||||
@@ -95,7 +95,7 @@ func GetFriendIDListFromCache(ctx context.Context, userID string) (friendIDList
|
||||
|
||||
func DelFriendIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(friendRelationCache + userID)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func GetBlackListFromCache(ctx context.Context, userID string) (blackIDList []st
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "blackIDList", blackIDList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "blackIDList", blackIDList)
|
||||
}()
|
||||
blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
|
||||
if err != nil {
|
||||
@@ -125,7 +125,7 @@ func GetBlackListFromCache(ctx context.Context, userID string) (blackIDList []st
|
||||
|
||||
func DelBlackIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ctx", ctx)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ctx", ctx)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(blackListCache + userID)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func GetJoinedGroupIDListFromCache(ctx context.Context, userID string) (joinedGr
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedGroupList", joinedGroupList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedGroupList", joinedGroupList)
|
||||
}()
|
||||
joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second*30*60, getJoinedGroupIDList)
|
||||
if err != nil {
|
||||
@@ -155,7 +155,7 @@ func GetJoinedGroupIDListFromCache(ctx context.Context, userID string) (joinedGr
|
||||
|
||||
func DelJoinedGroupIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(joinedGroupListCache + userID)
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func GetGroupMemberIDListFromCache(ctx context.Context, groupID string) (groupMe
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMemberIDList", groupMemberIDList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMemberIDList", groupMemberIDList)
|
||||
}()
|
||||
groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second*30*60, f)
|
||||
if err != nil {
|
||||
@@ -198,7 +198,7 @@ func GetGroupMemberIDListFromCache(ctx context.Context, groupID string) (groupMe
|
||||
|
||||
func DelGroupMemberIDListFromCache(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(groupCache + groupID)
|
||||
}
|
||||
@@ -216,7 +216,7 @@ func GetUserInfoFromCache(ctx context.Context, userID string) (userInfo *imdb.Us
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "userInfo", *userInfo)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "userInfo", *userInfo)
|
||||
}()
|
||||
userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second*30*60, getUserInfo)
|
||||
if err != nil {
|
||||
@@ -241,7 +241,7 @@ func GetUserInfoFromCacheBatch(ctx context.Context, userIDs []string) ([]*imdb.U
|
||||
|
||||
func DelUserInfoFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(userInfoCache + userID)
|
||||
}
|
||||
@@ -259,7 +259,7 @@ func GetGroupMemberInfoFromCache(ctx context.Context, groupID, userID string) (g
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
}()
|
||||
groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second*30*60, getGroupMemberInfo)
|
||||
if err != nil {
|
||||
@@ -272,14 +272,14 @@ func GetGroupMemberInfoFromCache(ctx context.Context, groupID, userID string) (g
|
||||
|
||||
func DelGroupMemberInfoFromCache(ctx context.Context, groupID, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID)
|
||||
}
|
||||
|
||||
func GetGroupMembersInfoFromCache(ctx context.Context, count, offset int32, groupID string) (groupMembers []*imdb.GroupMember, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "count", count, "offset", offset, "groupID", groupID, "groupMember", groupMembers)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "count", count, "offset", offset, "groupID", groupID, "groupMember", groupMembers)
|
||||
}()
|
||||
groupMemberIDList, err := GetGroupMemberIDListFromCache(ctx, groupID)
|
||||
if err != nil {
|
||||
@@ -326,7 +326,7 @@ func GetGroupMembersInfoFromCache(ctx context.Context, count, offset int32, grou
|
||||
|
||||
func GetAllGroupMembersInfoFromCache(ctx context.Context, groupID string) (groupMembers []*imdb.GroupMember, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMembers", groupMembers)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMembers", groupMembers)
|
||||
}()
|
||||
getGroupMemberInfo := func() (string, error) {
|
||||
groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID)
|
||||
@@ -349,7 +349,7 @@ func GetAllGroupMembersInfoFromCache(ctx context.Context, groupID string) (group
|
||||
|
||||
func DelAllGroupMembersInfoFromCache(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
|
||||
}
|
||||
@@ -368,7 +368,7 @@ func GetGroupInfoFromCache(ctx context.Context, groupID string) (groupInfo *imdb
|
||||
}
|
||||
groupInfo = &imdb.Group{}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupInfo", groupInfo)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupInfo", groupInfo)
|
||||
}()
|
||||
groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second*30*60, getGroupInfo)
|
||||
if err != nil {
|
||||
@@ -380,7 +380,7 @@ func GetGroupInfoFromCache(ctx context.Context, groupID string) (groupInfo *imdb
|
||||
|
||||
func DelGroupInfoFromCache(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID)
|
||||
}
|
||||
@@ -398,7 +398,7 @@ func GetAllFriendsInfoFromCache(ctx context.Context, userID string) (friends []*
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "friends", friends)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "friends", friends)
|
||||
}()
|
||||
allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second*30*60, getAllFriendInfo)
|
||||
if err != nil {
|
||||
@@ -410,7 +410,7 @@ func GetAllFriendsInfoFromCache(ctx context.Context, userID string) (friends []*
|
||||
|
||||
func DelAllFriendsInfoFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
|
||||
}
|
||||
@@ -478,7 +478,7 @@ func GetJoinedSuperGroupListFromCache(ctx context.Context, userID string) (joine
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedSuperGroupIDs", joinedSuperGroupIDs)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedSuperGroupIDs", joinedSuperGroupIDs)
|
||||
}()
|
||||
joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second*30*60, getJoinedSuperGroupIDList)
|
||||
if err != nil {
|
||||
@@ -490,7 +490,7 @@ func GetJoinedSuperGroupListFromCache(ctx context.Context, userID string) (joine
|
||||
|
||||
func DelJoinedSuperGroupIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(joinedSuperGroupListCache + userID)
|
||||
}
|
||||
@@ -518,7 +518,7 @@ func GetGroupMemberListHashFromCache(ctx context.Context, groupID string) (hashC
|
||||
return strconv.Itoa(int(bi.Uint64())), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "hashCodeUint64", hashCodeUint64)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "hashCodeUint64", hashCodeUint64)
|
||||
}()
|
||||
hashCodeStr, err := db.DB.Rc.Fetch(groupMemberListHashCache+groupID, time.Second*30*60, generateHash)
|
||||
if err != nil {
|
||||
@@ -530,7 +530,7 @@ func GetGroupMemberListHashFromCache(ctx context.Context, groupID string) (hashC
|
||||
|
||||
func DelGroupMemberListHashFromCache(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(groupMemberListHashCache + groupID)
|
||||
}
|
||||
@@ -544,7 +544,7 @@ func GetGroupMemberNumFromCache(ctx context.Context, groupID string) (num int, e
|
||||
return strconv.Itoa(int(num)), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "num", num)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "num", num)
|
||||
}()
|
||||
groupMember, err := db.DB.Rc.Fetch(groupMemberNumCache+groupID, time.Second*30*60, getGroupMemberNum)
|
||||
if err != nil {
|
||||
@@ -555,7 +555,7 @@ func GetGroupMemberNumFromCache(ctx context.Context, groupID string) (num int, e
|
||||
|
||||
func DelGroupMemberNumFromCache(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return db.DB.Rc.TagAsDeleted(groupMemberNumCache + groupID)
|
||||
}
|
||||
@@ -574,7 +574,7 @@ func GetUserConversationIDListFromCache(ctx context.Context, userID string) (con
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "conversationIDs", conversationIDs)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "conversationIDs", conversationIDs)
|
||||
}()
|
||||
conversationIDListStr, err := db.DB.Rc.Fetch(conversationIDListCache+userID, time.Second*30*60, getConversationIDList)
|
||||
err = json.Unmarshal([]byte(conversationIDListStr), &conversationIDs)
|
||||
@@ -586,7 +586,7 @@ func GetUserConversationIDListFromCache(ctx context.Context, userID string) (con
|
||||
|
||||
func DelUserConversationIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err")
|
||||
}
|
||||
@@ -604,7 +604,7 @@ func GetConversationFromCache(ctx context.Context, ownerUserID, conversationID s
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID, "conversation", *conversation)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID, "conversation", *conversation)
|
||||
}()
|
||||
conversationStr, err := db.DB.Rc.Fetch(conversationCache+ownerUserID+":"+conversationID, time.Second*30*60, getConversation)
|
||||
if err != nil {
|
||||
@@ -617,7 +617,7 @@ func GetConversationFromCache(ctx context.Context, ownerUserID, conversationID s
|
||||
|
||||
func GetConversationsFromCache(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []imdb.Conversation, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationIDs", conversationIDs, "conversations", conversations)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationIDs", conversationIDs, "conversations", conversations)
|
||||
}()
|
||||
for _, conversationID := range conversationIDs {
|
||||
conversation, err := GetConversationFromCache(ctx, ownerUserID, conversationID)
|
||||
@@ -631,7 +631,7 @@ func GetConversationsFromCache(ctx context.Context, ownerUserID string, conversa
|
||||
|
||||
func GetUserAllConversationList(ctx context.Context, ownerUserID string) (conversations []imdb.Conversation, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversations", conversations)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversations", conversations)
|
||||
}()
|
||||
IDList, err := GetUserConversationIDListFromCache(ctx, ownerUserID)
|
||||
if err != nil {
|
||||
@@ -651,7 +651,7 @@ func GetUserAllConversationList(ctx context.Context, ownerUserID string) (conver
|
||||
|
||||
func DelConversationFromCache(ctx context.Context, ownerUserID, conversationID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID)
|
||||
}()
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
|
||||
}
|
||||
@@ -669,7 +669,7 @@ func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clien
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "sourceID", sourceID, "sessionType",
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "sourceID", sourceID, "sessionType",
|
||||
sessionType, "clientMsgID", clientMsgID, "firstModifyTime", firstModifyTime, "extendMsg", extendMsg)
|
||||
}()
|
||||
extendMsgStr, err := db.DB.Rc.Fetch(extendMsgCache+clientMsgID, time.Second*30*60, getExtendMsg)
|
||||
@@ -683,7 +683,7 @@ func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clien
|
||||
|
||||
func DelExtendMsg(ctx context.Context, clientMsgID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "clientMsgID", clientMsgID)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "clientMsgID", clientMsgID)
|
||||
}()
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgCache+clientMsgID), "DelExtendMsg err")
|
||||
}
|
||||
|
||||
+121
-1
@@ -2,7 +2,9 @@ package log
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"bufio"
|
||||
"context"
|
||||
|
||||
//"bufio"
|
||||
"fmt"
|
||||
@@ -16,6 +18,7 @@ import (
|
||||
)
|
||||
|
||||
var logger *Logger
|
||||
var ctxLogger *Logger
|
||||
|
||||
type Logger struct {
|
||||
*logrus.Logger
|
||||
@@ -24,12 +27,35 @@ type Logger struct {
|
||||
|
||||
func init() {
|
||||
logger = loggerInit("")
|
||||
|
||||
ctxLogger = ctxLoggerInit("")
|
||||
}
|
||||
|
||||
func NewPrivateLog(moduleName string) {
|
||||
logger = loggerInit(moduleName)
|
||||
}
|
||||
|
||||
func ctxLoggerInit(moduleName string) *Logger {
|
||||
var ctxLogger = logrus.New()
|
||||
ctxLogger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
||||
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
writer := bufio.NewWriter(src)
|
||||
ctxLogger.SetOutput(writer)
|
||||
ctxLogger.SetFormatter(&logrus.JSONFormatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||
DataKey: "args",
|
||||
FieldMap: nil,
|
||||
CallerPrettyfier: nil,
|
||||
PrettyPrint: false,
|
||||
})
|
||||
return &Logger{
|
||||
ctxLogger,
|
||||
os.Getpid(),
|
||||
}
|
||||
}
|
||||
|
||||
func loggerInit(moduleName string) *Logger {
|
||||
var logger = logrus.New()
|
||||
//All logs will be printed
|
||||
@@ -44,11 +70,13 @@ func loggerInit(moduleName string) *Logger {
|
||||
logger.SetOutput(writer)
|
||||
// logger.SetOutput(os.Stdout)
|
||||
//Log Console Print Style Setting
|
||||
|
||||
logger.SetFormatter(&nested.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||
HideKeys: false,
|
||||
FieldsOrder: []string{"PID", "FilePath", "OperationID"},
|
||||
})
|
||||
|
||||
//File name and line number display hook
|
||||
logger.AddHook(newFileHook())
|
||||
|
||||
@@ -200,3 +228,95 @@ func NewWarn(OperationID string, args ...interface{}) {
|
||||
"PID": logger.Pid,
|
||||
}).Warnln(args)
|
||||
}
|
||||
|
||||
func ShowLog(ctx context.Context) {
|
||||
t := ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo)
|
||||
OperationID := trace_log.GetOperationID(ctx)
|
||||
if ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo).GinCtx != nil {
|
||||
ctxLogger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": ctxLogger.Pid,
|
||||
}).Infoln("api: ", t.ApiName)
|
||||
} else {
|
||||
ctxLogger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": ctxLogger.Pid,
|
||||
}).Infoln("rpc: ", t.ApiName)
|
||||
}
|
||||
for _, v := range *t.Funcs {
|
||||
if v.Err != nil {
|
||||
ctxLogger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": ctxLogger.Pid,
|
||||
"FilePath": v.File,
|
||||
}).Errorln("func: ", v.FuncName, " args: ", v.Args, v.Err.Error())
|
||||
} else {
|
||||
switch v.LogLevel {
|
||||
case logrus.InfoLevel:
|
||||
ctxLogger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": ctxLogger.Pid,
|
||||
"FilePath": v.File,
|
||||
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
||||
case logrus.DebugLevel:
|
||||
ctxLogger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": ctxLogger.Pid,
|
||||
"FilePath": v.File,
|
||||
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
||||
case logrus.WarnLevel:
|
||||
ctxLogger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": ctxLogger.Pid,
|
||||
"FilePath": v.File,
|
||||
}).Warnln("func: ", v.FuncName, " args: ", v.Args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func InfoWithCtx(ctx context.Context, args ...interface{}) {
|
||||
t := ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo)
|
||||
OperationID := trace_log.GetOperationID(ctx)
|
||||
for _, v := range *t.Funcs {
|
||||
logger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": logger.Pid,
|
||||
}).Infoln(v.Args, args)
|
||||
}
|
||||
}
|
||||
|
||||
func DebugWithCtx(ctx context.Context, args ...interface{}) {
|
||||
t := ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo)
|
||||
OperationID := trace_log.GetOperationID(ctx)
|
||||
for _, v := range *t.Funcs {
|
||||
logger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": logger.Pid,
|
||||
}).Debugln(v.Args, args)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorWithCtx(ctx context.Context, args ...interface{}) {
|
||||
t := ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo)
|
||||
OperationID := trace_log.GetOperationID(ctx)
|
||||
for _, v := range *t.Funcs {
|
||||
if v.Err != nil {
|
||||
logger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": logger.Pid,
|
||||
}).Errorln(v.Err, v.Args, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WarnWithCtx(ctx context.Context, args ...interface{}) {
|
||||
t := ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo)
|
||||
OperationID := trace_log.GetOperationID(ctx)
|
||||
for _, v := range *t.Funcs {
|
||||
logger.WithFields(logrus.Fields{
|
||||
"OperationID": OperationID,
|
||||
"PID": logger.Pid,
|
||||
}).Warnln(v.Args, args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
||||
opUserID = opts[0]
|
||||
}
|
||||
ctx = trace_log.NewRpcCtx(ctx, funcName, operationID)
|
||||
defer trace_log.ShowLog(ctx)
|
||||
trace_log.SetContextInfo(ctx, funcName, err, "opUserID", opUserID, "rpcReq", rpcString(req))
|
||||
defer log.ShowLog(ctx)
|
||||
trace_log.SetCtxInfo(ctx, funcName, err, "opUserID", opUserID, "rpcReq", rpcString(req))
|
||||
resp, err = handler(ctx, req)
|
||||
if err != nil {
|
||||
trace_log.SetContextInfo(ctx, funcName, err)
|
||||
trace_log.SetCtxInfo(ctx, funcName, err)
|
||||
errInfo := constant.ToAPIErrWithErr(err)
|
||||
var code codes.Code
|
||||
if errInfo.ErrCode == 0 {
|
||||
@@ -58,7 +58,7 @@ func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
||||
}
|
||||
return nil, sta.Err()
|
||||
}
|
||||
trace_log.SetContextInfo(ctx, funcName, nil, "rpcResp", rpcString(resp))
|
||||
trace_log.SetCtxInfo(ctx, funcName, nil, "rpcResp", rpcString(resp))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ func CheckAccess(ctx context.Context, OpUserID string, OwnerUserID string) bool
|
||||
|
||||
func CheckAccessV2(ctx context.Context, OpUserID string, OwnerUserID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "OpUserID", OpUserID, "OwnerUserID", OwnerUserID)
|
||||
trace_log.SetCtxInfo(ctx, utils.GetFuncName(1), err, "OpUserID", OpUserID, "OwnerUserID", OwnerUserID)
|
||||
}()
|
||||
if utils.IsContain(OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
return nil
|
||||
|
||||
+36
-11
@@ -3,8 +3,11 @@ package trace_log
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc/status"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
//"errors"
|
||||
@@ -47,18 +50,24 @@ func ShowLog(ctx context.Context) {
|
||||
} else {
|
||||
log.Info(t.OperationID, "rpc: ", t.ApiName)
|
||||
}
|
||||
|
||||
for _, v := range *t.Funcs {
|
||||
if v.Err != nil {
|
||||
log.Error(t.OperationID, "func: ", v.FuncName, " args: ", v.Args, v.Err.Error())
|
||||
} else {
|
||||
log.Info(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
switch v.LogLevel {
|
||||
case logrus.InfoLevel:
|
||||
log.Info(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
case logrus.DebugLevel:
|
||||
log.Debug(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
case logrus.WarnLevel:
|
||||
log.Debug(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
SetContextInfo(ctx, funcName, err, args)
|
||||
SetCtxInfo(ctx, funcName, err, args)
|
||||
e := Unwrap(err)
|
||||
switch t := e.(type) {
|
||||
case *constant.ErrInfo:
|
||||
@@ -83,7 +92,7 @@ func WriteErrorResponse(ctx context.Context, funcName string, err error, args ..
|
||||
}
|
||||
|
||||
//func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
// SetContextInfo(ctx, funcName, err, args)
|
||||
// SetCtxInfo(ctx, funcName, err, args)
|
||||
// e := new(constant.ErrInfo)
|
||||
// switch {
|
||||
// case errors.As(err, &e):
|
||||
@@ -119,6 +128,8 @@ type FuncInfo struct {
|
||||
FuncName string
|
||||
Args Args
|
||||
Err error
|
||||
LogLevel logrus.Level
|
||||
File string
|
||||
}
|
||||
|
||||
type Args map[string]interface{}
|
||||
@@ -139,13 +150,32 @@ func (a Args) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
func SetContextInfo(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
func SetCtxDebug(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
SetContextInfo(ctx, funcName, logrus.DebugLevel, err, args)
|
||||
}
|
||||
|
||||
func SetCtxInfo(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
SetContextInfo(ctx, funcName, logrus.InfoLevel, err, args)
|
||||
}
|
||||
|
||||
func SetCtxWarn(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
SetContextInfo(ctx, funcName, logrus.WarnLevel, err, args)
|
||||
}
|
||||
|
||||
func SetContextInfo(ctx context.Context, funcName string, logLevel logrus.Level, err error, args ...interface{}) {
|
||||
t := ctx.Value(TraceLogKey).(*ApiInfo)
|
||||
var funcInfo FuncInfo
|
||||
funcInfo.Args = make(map[string]interface{})
|
||||
argsHandle(args, funcInfo.Args)
|
||||
funcInfo.FuncName = funcName
|
||||
funcInfo.Err = err
|
||||
funcInfo.LogLevel = logLevel
|
||||
_, file, line, _ := runtime.Caller(2)
|
||||
i := strings.SplitAfter(file, "/")
|
||||
if len(i) > 3 {
|
||||
file = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(line)
|
||||
}
|
||||
funcInfo.File = file
|
||||
*t.Funcs = append(*t.Funcs, funcInfo)
|
||||
}
|
||||
|
||||
@@ -172,7 +202,7 @@ func SetRpcRespInfo(ctx context.Context, funcName string, resp string) {
|
||||
}
|
||||
|
||||
func SetSuccess(ctx context.Context, funcName string, data interface{}) {
|
||||
SetContextInfo(ctx, funcName, nil, "data", data)
|
||||
SetCtxInfo(ctx, funcName, nil, "data", data)
|
||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "errDtl": "", "data": data})
|
||||
}
|
||||
|
||||
@@ -185,8 +215,3 @@ func argsHandle(args []interface{}, fields map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetApiErr(errCode int32, errMsg string) constant.ErrInfo {
|
||||
|
||||
return constant.ErrInfo{ErrCode: errCode, ErrMsg: errMsg}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user