Add auth.user.name to logging context

This commit is contained in:
Richard 2015-04-14 16:07:23 -07:00
parent 1c22aefa5e
commit cb6a6125f6
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 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 { type challenge struct {

View file

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