Add auth.user.name to logging context

This commit is contained in:
Richard 2015-04-14 16:07:23 -07:00
parent e5eddbc762
commit 9898552656
2 changed files with 4 additions and 2 deletions

View File

@ -66,7 +66,7 @@ func (ac *accessController) Authorized(ctx context.Context, accessRecords ...aut
return nil, &challenge
}
return context.WithValue(ctx, "auth.user", auth.UserInfo{Name: "silly"}), nil
return auth.WithUser(ctx, auth.UserInfo{Name: "silly"}), nil
}
type challenge struct {

View File

@ -324,6 +324,9 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler {
return
}
// Add username to request logging
context.Context = ctxu.WithLogger(context.Context, ctxu.GetLogger(context.Context, "auth.user.name"))
if app.nameRequired(r) {
repository, err := app.registry.Repository(context, getName(context))
@ -456,7 +459,6 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont
// should be replaced by another, rather than replacing the context on a
// mutable object.
context.Context = ctx
return nil
}