From 686c2fbab7607d42183ae685a27ea3d7dce8c3f6 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 27 Apr 2018 12:49:45 -0700 Subject: 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. --- app/email_batching.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'app/email_batching.go') diff --git a/app/email_batching.go b/app/email_batching.go index 07adda674..e1ea7abb5 100644 --- a/app/email_batching.go +++ b/app/email_batching.go @@ -10,12 +10,12 @@ import ( "sync" "time" + "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "net/http" - l4g "github.com/alecthomas/log4go" "github.com/nicksnyder/go-i18n/i18n" ) @@ -41,7 +41,7 @@ func (a *App) AddNotificationEmailToBatch(user *model.User, post *model.Post, te } if !a.EmailBatching.Add(user, post, team) { - l4g.Error(utils.T("api.email_batching.add_notification_email_to_batch.channel_full.app_error")) + mlog.Error("Email batching job's receiving channel was full. Please increase the EmailBatchingBufferSize.") return model.NewAppError("AddNotificationEmailToBatch", "api.email_batching.add_notification_email_to_batch.channel_full.app_error", nil, "", http.StatusInternalServerError) } @@ -71,7 +71,7 @@ func NewEmailBatchingJob(a *App, bufferSize int) *EmailBatchingJob { } func (job *EmailBatchingJob) Start() { - l4g.Debug(utils.T("api.email_batching.start.starting"), *job.app.Config().EmailSettings.EmailBatchingInterval) + mlog.Debug(fmt.Sprintf("Email batching job starting. Checking for pending emails every %v seconds.", *job.app.Config().EmailSettings.EmailBatchingInterval)) newTask := model.CreateRecurringTask(EMAIL_BATCHING_TASK_NAME, job.CheckPendingEmails, time.Duration(*job.app.Config().EmailSettings.EmailBatchingInterval)*time.Second) job.taskMutex.Lock() @@ -107,7 +107,7 @@ func (job *EmailBatchingJob) CheckPendingEmails() { // without actually sending emails job.checkPendingNotifications(time.Now(), job.app.sendBatchedEmailNotification) - l4g.Debug(utils.T("api.email_batching.check_pending_emails.finished_running"), len(job.pendingNotifications)) + mlog.Debug(fmt.Sprintf("Email batching job ran. %v user(s) still have notifications pending.", len(job.pendingNotifications))) } func (job *EmailBatchingJob) handleNewNotifications() { @@ -141,7 +141,7 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu } tchan := job.app.Srv.Store.Team().GetByName(notifications[0].teamName) if result := <-tchan; result.Err != nil { - l4g.Error("Unable to find Team id for notification", result.Err) + mlog.Error(fmt.Sprint("Unable to find Team id for notification", result.Err)) continue } else if team, ok := result.Data.(*model.Team); ok { inspectedTeamNames[notification.teamName] = team.Id @@ -151,12 +151,12 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu // all queued notifications mchan := job.app.Srv.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId) if result := <-mchan; result.Err != nil { - l4g.Error("Unable to find ChannelMembers for user", result.Err) + mlog.Error(fmt.Sprint("Unable to find ChannelMembers for user", result.Err)) continue } else if channelMembers, ok := result.Data.(*model.ChannelMembers); ok { for _, channelMember := range *channelMembers { if channelMember.LastViewedAt >= batchStartTime { - l4g.Debug("Deleted notifications for user %s", userId) + mlog.Debug(fmt.Sprintf("Deleted notifications for user %s", userId), mlog.String("user_id", userId)) delete(job.pendingNotifications, userId) break } @@ -198,7 +198,7 @@ func (a *App) sendBatchedEmailNotification(userId string, notifications []*batch var user *model.User if result := <-uchan; result.Err != nil { - l4g.Warn("api.email_batching.send_batched_email_notification.user.app_error") + mlog.Warn("api.email_batching.send_batched_email_notification.user.app_error") return } else { user = result.Data.(*model.User) @@ -212,7 +212,7 @@ func (a *App) sendBatchedEmailNotification(userId string, notifications []*batch var sender *model.User schan := a.Srv.Store.User().Get(notification.post.UserId) if result := <-schan; result.Err != nil { - l4g.Warn(utils.T("api.email_batching.render_batched_post.sender.app_error")) + mlog.Warn("Unable to find sender of post for batched email notification") continue } else { sender = result.Data.(*model.User) @@ -221,7 +221,7 @@ func (a *App) sendBatchedEmailNotification(userId string, notifications []*batch var channel *model.Channel cchan := a.Srv.Store.Channel().Get(notification.post.ChannelId, true) if result := <-cchan; result.Err != nil { - l4g.Warn(utils.T("api.email_batching.render_batched_post.channel.app_error")) + mlog.Warn("Unable to find channel of post for batched email notification") continue } else { channel = result.Data.(*model.Channel) @@ -250,7 +250,7 @@ func (a *App) sendBatchedEmailNotification(userId string, notifications []*batch body.Props["BodyText"] = translateFunc("api.email_batching.send_batched_email_notification.body_text", len(notifications)) if err := a.SendMail(user.Email, subject, body.Render()); err != nil { - l4g.Warn(utils.T("api.email_batchings.send_batched_email_notification.send.app_error"), user.Email, err) + mlog.Warn(fmt.Sprint("api.email_batchings.send_batched_email_notification.send.app_error FIXME: NOT FOUND IN TRANSLATIONS FILE", user.Email, err)) } } -- cgit v1.2.3-1-g7c22