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()))
|
appInstance := app.New(app.ServerConnector(h.Srv.Channels()))
|
||||||
|
|
||||||
|
c := &Context{
|
||||||
|
AppContext: &request.Context{},
|
||||||
|
App: appInstance,
|
||||||
|
}
|
||||||
|
|
||||||
requestID := model.NewId()
|
requestID := model.NewId()
|
||||||
var statusCode string
|
var statusCode string
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -157,6 +162,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
mlog.String("url", r.URL.Path),
|
mlog.String("url", r.URL.Path),
|
||||||
mlog.String("request_id", requestID),
|
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
|
// Websockets are returning status code 0 to requests after closing the socket
|
||||||
if statusCode != "0" {
|
if statusCode != "0" {
|
||||||
responseLogFields = append(responseLogFields, mlog.String("status_code", statusCode))
|
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...)
|
mlog.Debug("Received HTTP request", responseLogFields...)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
c := &Context{
|
|
||||||
AppContext: &request.Context{},
|
|
||||||
App: appInstance,
|
|
||||||
}
|
|
||||||
|
|
||||||
t, _ := i18n.GetTranslationsAndLocaleFromRequest(r)
|
t, _ := i18n.GetTranslationsAndLocaleFromRequest(r)
|
||||||
c.AppContext = request.NewContext(
|
c.AppContext = request.NewContext(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
|
Loading…
Reference in New Issue
Block a user