Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/channels/api4/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,15 +703,15 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
}
}

c.AppContext.WithLogger(c.AppContext.Logger().With(
c.AppContext = c.AppContext.WithLogFields(
mlog.String("type", model.NotificationTypePush),
mlog.String("ack_id", ack.Id),
mlog.String("push_type", ack.NotificationType),
mlog.String("post_id", ack.PostId),
mlog.String("ack_type", ack.NotificationType),
mlog.String("device_type", ack.ClientPlatform),
mlog.Int("received_at", ack.ClientReceivedAt),
))
)
err := c.App.SendAckToPushProxy(c.AppContext, &ack)
if ack.IsIdLoaded {
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion server/channels/app/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (a *App) ExecuteCommand(rctx request.CTX, args *model.CommandArgs) (*model.
if !strings.HasPrefix(trigger, "/") {
return nil, model.NewAppError("command", "api.command.execute_command.format.app_error", map[string]any{"Trigger": trigger}, "", http.StatusBadRequest)
}

trigger = strings.TrimPrefix(trigger, "/")

clientTriggerId, triggerId, appErr := model.GenerateTriggerId(args.UserId, a.AsymmetricSigningKey())
Expand Down Expand Up @@ -470,7 +471,7 @@ func (a *App) tryExecuteCustomCommand(rctx request.CTX, args *model.CommandArgs,
return nil, nil, nil
}

rctx.Logger().Debug("Executing command", mlog.String("command", trigger), mlog.String("user_id", args.UserId))
rctx = rctx.WithLogFields(mlog.String("command_id", cmd.Id))

p := url.Values{}
p.Set("token", cmd.Token)
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (a *App) SaveComplianceReport(rctx request.CTX, job *model.Compliance) (*mo

job.Type = model.ComplianceTypeAdhoc

rctx = rctx.WithLogger(rctx.Logger().With(job.LoggerFields()...))
rctx = rctx.WithLogFields(job.LoggerFields()...)

job, err := a.Srv().Store().Compliance().Save(job)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,11 @@ func (a *App) UploadFileX(rctx request.CTX, channelID, name string, input io.Rea
o(t)
}

rctx = rctx.WithLogger(rctx.Logger().With(
rctx = rctx.WithLogFields(
mlog.String("file_name", name),
mlog.String("channel_id", channelID),
mlog.String("user_id", t.UserId),
))
)

if *a.Config().FileSettings.DriverName == "" {
return nil, t.newAppError("api.file.upload_file.storage.app_error", http.StatusNotImplemented)
Expand Down
2 changes: 2 additions & 0 deletions server/channels/app/plugin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func (a *App) tryExecutePluginCommand(rctx request.CTX, args *model.CommandArgs)
return nil, nil, nil
}

rctx = rctx.WithLogFields(mlog.String("plugin_id", matched.PluginId))

pluginsEnvironment := a.GetPluginsEnvironment()
if pluginsEnvironment == nil {
return nil, nil, nil
Expand Down
4 changes: 1 addition & 3 deletions server/channels/app/plugin_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ func (ch *Channels) servePluginRequest(w http.ResponseWriter, r *http.Request, h
r.Header.Del(model.HeaderAuth)

rctx = rctx.
WithLogger(rctx.Logger().With(
mlog.String("user_id", session.UserId),
)).
WithLogFields(mlog.String("user_id", session.UserId)).
WithSession(session)

// If MFA is required and user has not activated it, treat it as unauthenticated
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ func (a *App) SetPostReminder(rctx request.CTX, postID, userID string, targetTim
}

func (a *App) CheckPostReminders(rctx request.CTX) {
rctx = rctx.WithLogger(rctx.Logger().With(mlog.String("component", "post_reminders")))
rctx = rctx.WithLogFields(mlog.String("component", "post_reminders"))
systemBot, appErr := a.GetSystemBot(rctx)
if appErr != nil {
rctx.Logger().Error("Failed to get system bot", mlog.Err(appErr))
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/scheduled_post_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
)

func (a *App) ProcessScheduledPosts(rctx request.CTX) {
rctx = rctx.WithLogger(rctx.Logger().With(mlog.String("component", "scheduled_post_job")))
rctx = rctx.WithLogFields(mlog.String("component", "scheduled_post_job"))

if !*a.Config().ServiceSettings.ScheduledPosts {
return
Expand Down
6 changes: 6 additions & 0 deletions server/public/shared/request/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func (c *Context) WithLogger(logger mlog.LoggerIFace) CTX {
return rctx
}

// WithLogFields returns a new context with the given fields added to the logger.
func (c *Context) WithLogFields(fields ...mlog.Field) CTX {
return c.WithLogger(c.logger.With(fields...))
}

func (c *Context) With(f func(ctx CTX) CTX) CTX {
return f(c)
}
Expand All @@ -194,6 +199,7 @@ type CTX interface {
WithUserAgent(string) CTX
WithAcceptLanguage(string) CTX
WithLogger(mlog.LoggerIFace) CTX
WithLogFields(fields ...mlog.Field) CTX
WithContext(ctx context.Context) CTX
With(func(ctx CTX) CTX) CTX
}
Loading