mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-37511 Add userid to http logs (#24516)
* include user_id in http logs
This commit is contained in:
parent
5ccc039278
commit
5e7d1c6f9e
@ -149,6 +149,11 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
appInstance := app.New(app.ServerConnector(h.Srv.Channels()))
|
||||
|
||||
c := &Context{
|
||||
AppContext: &request.Context{},
|
||||
App: appInstance,
|
||||
}
|
||||
|
||||
requestID := model.NewId()
|
||||
var statusCode string
|
||||
defer func() {
|
||||
@ -157,6 +162,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
mlog.String("url", r.URL.Path),
|
||||
mlog.String("request_id", requestID),
|
||||
}
|
||||
// if there is a session then include the user_id
|
||||
if c.AppContext.Session() != nil {
|
||||
responseLogFields = append(responseLogFields, mlog.String("user_id", c.AppContext.Session().UserId))
|
||||
}
|
||||
// Websockets are returning status code 0 to requests after closing the socket
|
||||
if statusCode != "0" {
|
||||
responseLogFields = append(responseLogFields, mlog.String("status_code", statusCode))
|
||||
@ -164,11 +173,6 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
mlog.Debug("Received HTTP request", responseLogFields...)
|
||||
}()
|
||||
|
||||
c := &Context{
|
||||
AppContext: &request.Context{},
|
||||
App: appInstance,
|
||||
}
|
||||
|
||||
t, _ := i18n.GetTranslationsAndLocaleFromRequest(r)
|
||||
c.AppContext = request.NewContext(
|
||||
context.Background(),
|
||||
|
Loading…
Reference in New Issue
Block a user