Structured logging (#8673)
* Implementing structured logging * Changes to en.json to allow refactor to run. * Fixing global logger * Structured logger initalization. * Add caller. * Do some log redirection. * Auto refactor * Cleaning up l4g reference and removing dependancy. * Removing junk. * Copyright headers. * Fixing tests * Revert "Changes to en.json to allow refactor to run." This reverts commit fd8249e99bcad0231e6ea65cd77c32aae9a54026. * Fixing some auto refactor strangeness and typo. * Making keys more human readable.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2acbc77d78
Коммит
686c2fbab7
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -60,17 +60,17 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, channelRole s
|
||||
err = cmResult.Err
|
||||
}
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, townSquare.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages {
|
||||
if requestor == nil {
|
||||
if err := a.postJoinTeamMessage(user, townSquare); err != nil {
|
||||
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||
mlog.Error(fmt.Sprint("Failed to post join/leave message", err))
|
||||
}
|
||||
} else {
|
||||
if err := a.postAddToTeamMessage(requestor, user, townSquare, ""); err != nil {
|
||||
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||
mlog.Error(fmt.Sprint("Failed to post join/leave message", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,16 +93,16 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, channelRole s
|
||||
err = cmResult.Err
|
||||
}
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, offTopic.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
|
||||
if requestor == nil {
|
||||
if err := a.postJoinChannelMessage(user, offTopic); err != nil {
|
||||
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||
mlog.Error(fmt.Sprint("Failed to post join/leave message", err))
|
||||
}
|
||||
} else {
|
||||
if err := a.PostAddToChannelMessage(requestor, user, offTopic, ""); err != nil {
|
||||
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||
mlog.Error(fmt.Sprint("Failed to post join/leave message", err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
||||
return nil, cmresult.Err
|
||||
}
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(channel.CreatorId)
|
||||
@@ -227,10 +227,10 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(otherUserId, channel.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
|
||||
return channel, nil
|
||||
@@ -258,7 +258,7 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
||||
}
|
||||
}
|
||||
|
||||
l4g.Error("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId)
|
||||
mlog.Error(fmt.Sprintf("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId), mlog.String("user_id", userId))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
||||
return nil, result.Err
|
||||
}
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,19 +413,19 @@ func (a *App) PatchChannel(channel *model.Channel, patch *model.ChannelPatch, us
|
||||
|
||||
if oldChannelDisplayName != channel.DisplayName {
|
||||
if err := a.PostUpdateChannelDisplayNameMessage(userId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if channel.Header != oldChannelHeader {
|
||||
if err := a.PostUpdateChannelHeaderMessage(userId, channel, oldChannelHeader, channel.Header); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if channel.Purpose != oldChannelPurpose {
|
||||
if err := a.PostUpdateChannelPurposeMessage(userId, channel, oldChannelPurpose, channel.Purpose); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,21 +536,21 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err)
|
||||
mlog.Error(fmt.Sprintf("Failed to post archive message %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
now := model.GetMillis()
|
||||
for _, hook := range incomingHooks {
|
||||
if result := <-a.Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil {
|
||||
l4g.Error(utils.T("api.channel.delete_channel.incoming_webhook.error"), hook.Id)
|
||||
mlog.Error(fmt.Sprintf("Encountered error deleting incoming webhook, id=%v", hook.Id))
|
||||
}
|
||||
a.InvalidateCacheForWebhook(hook.Id)
|
||||
}
|
||||
|
||||
for _, hook := range outgoingHooks {
|
||||
if result := <-a.Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil {
|
||||
l4g.Error(utils.T("api.channel.delete_channel.outgoing_webhook.error"), hook.Id)
|
||||
mlog.Error(fmt.Sprintf("Encountered error deleting outgoing webhook, id=%v", hook.Id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,13 +594,13 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
||||
Roles: model.CHANNEL_USER_ROLE_ID,
|
||||
}
|
||||
if result := <-a.Srv.Store.Channel().SaveMember(newMember); result.Err != nil {
|
||||
l4g.Error("Failed to add member user_id=%v channel_id=%v err=%v", user.Id, channel.Id, result.Err)
|
||||
mlog.Error(fmt.Sprintf("Failed to add member user_id=%v channel_id=%v err=%v", user.Id, channel.Id, result.Err), mlog.String("user_id", user.Id))
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
a.WaitForChannelMembership(channel.Id, user.Id)
|
||||
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
@@ -1449,10 +1449,10 @@ func (a *App) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.
|
||||
|
||||
channel := result.Data.(*model.Channel)
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId1, channel.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId2, channel.Id, model.GetMillis()); result.Err != nil {
|
||||
l4g.Warn("Failed to update ChannelMemberHistory table %v", result.Err)
|
||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||
}
|
||||
|
||||
return channel, nil
|
||||
|
||||
Ссылка в новой задаче
Block a user