Manager: use logger from context instead of constructing a new one
This makes the logs more consistent, and any log that's bound to a HTTP request will have info about that request.
This commit is contained in:
parent
bff5e30421
commit
89d00dcba5
@ -9,6 +9,7 @@ import (
|
|||||||
oapi_middle "github.com/deepmap/oapi-codegen/pkg/middleware"
|
oapi_middle "github.com/deepmap/oapi-codegen/pkg/middleware"
|
||||||
"github.com/getkin/kin-openapi/openapi3filter"
|
"github.com/getkin/kin-openapi/openapi3filter"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
"git.blender.org/flamenco/internal/manager/persistence"
|
"git.blender.org/flamenco/internal/manager/persistence"
|
||||||
@ -63,6 +64,15 @@ func WorkerAuth(ctx context.Context, authInfo *openapi3filter.AuthenticationInpu
|
|||||||
func requestWorkerStore(e echo.Context, w *persistence.Worker) {
|
func requestWorkerStore(e echo.Context, w *persistence.Worker) {
|
||||||
req := e.Request()
|
req := e.Request()
|
||||||
reqCtx := context.WithValue(req.Context(), workerKey, w)
|
reqCtx := context.WithValue(req.Context(), workerKey, w)
|
||||||
|
|
||||||
|
// Update the logger in this context to reflect the Worker.
|
||||||
|
l := zerolog.Ctx(reqCtx)
|
||||||
|
l.UpdateContext(func(c zerolog.Context) zerolog.Context {
|
||||||
|
return c.
|
||||||
|
Str("wUUID", w.UUID).
|
||||||
|
Str("wName", w.Name)
|
||||||
|
})
|
||||||
|
|
||||||
e.SetRequest(req.WithContext(reqCtx))
|
e.SetRequest(req.WithContext(reqCtx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,16 +9,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func requestLogger(e echo.Context) zerolog.Logger {
|
func requestLogger(e echo.Context) zerolog.Logger {
|
||||||
logCtx := log.With().
|
logger := log.Ctx(e.Request().Context())
|
||||||
Str("remoteAddr", e.RealIP()).
|
return *logger
|
||||||
Str("userAgent", e.Request().UserAgent())
|
|
||||||
|
|
||||||
worker := requestWorker(e)
|
|
||||||
if worker != nil {
|
|
||||||
logCtx = logCtx.
|
|
||||||
Str("wUUID", worker.UUID).
|
|
||||||
Str("wName", worker.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return logCtx.Logger()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user