Tweak some logging

This commit is contained in:
Sybren A. Stüvel 2022-03-01 15:30:51 +01:00
parent 0235ffcb4a
commit bbc6a3f69e
3 changed files with 10 additions and 10 deletions

View File

@ -28,26 +28,25 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"gitlab.com/blender/flamenco-ng-poc/internal/manager/persistence" "gitlab.com/blender/flamenco-ng-poc/internal/manager/persistence"
"gitlab.com/blender/flamenco-ng-poc/pkg/api" "gitlab.com/blender/flamenco-ng-poc/pkg/api"
) )
func (f *Flamenco) GetJobTypes(e echo.Context) error { func (f *Flamenco) GetJobTypes(e echo.Context) error {
logger := requestLogger(e)
if f.jobCompiler == nil { if f.jobCompiler == nil {
log.Error().Msg("Flamenco is running without job compiler") logger.Error().Msg("Flamenco is running without job compiler")
return sendAPIError(e, http.StatusInternalServerError, "no job types available") return sendAPIError(e, http.StatusInternalServerError, "no job types available")
} }
logger.Debug().Msg("listing job types")
jobTypes := f.jobCompiler.ListJobTypes() jobTypes := f.jobCompiler.ListJobTypes()
return e.JSON(http.StatusOK, &jobTypes) return e.JSON(http.StatusOK, &jobTypes)
} }
func (f *Flamenco) SubmitJob(e echo.Context) error { func (f *Flamenco) SubmitJob(e echo.Context) error {
// TODO: move this into some middleware. logger := requestLogger(e)
logger := log.With().
Str("ip", e.RealIP()).
Logger()
var job api.SubmitJobJSONRequestBody var job api.SubmitJobJSONRequestBody
if err := e.Bind(&job); err != nil { if err := e.Bind(&job); err != nil {
@ -89,9 +88,8 @@ func (f *Flamenco) SubmitJob(e echo.Context) error {
} }
func (f *Flamenco) FetchJob(e echo.Context, jobId string) error { func (f *Flamenco) FetchJob(e echo.Context, jobId string) error {
// TODO: move this into some middleware.
logger := requestLogger(e).With(). logger := requestLogger(e).With().
Str("job_id", jobId). Str("job", jobId).
Logger() Logger()
if _, err := uuid.Parse(jobId); err != nil { if _, err := uuid.Parse(jobId); err != nil {

View File

@ -48,7 +48,7 @@ func SwaggerValidator(swagger *openapi3.T, persist PersistenceService) echo.Midd
// Skip OAPI validation when the request is not for the OAPI interface. // Skip OAPI validation when the request is not for the OAPI interface.
Skipper: func(e echo.Context) bool { Skipper: func(e echo.Context) bool {
isOapi := isOpenAPIPath(swagger, e.Path()) isOapi := isOpenAPIPath(swagger, e.Path())
log.Debug(). log.Trace().
Bool("isOpenAPI", isOapi). Bool("isOpenAPI", isOapi).
Str("path", e.Path()). Str("path", e.Path()).
Msg("checking validation skipperoo") Msg("checking validation skipperoo")

View File

@ -27,7 +27,9 @@ import (
) )
func requestLogger(e echo.Context) zerolog.Logger { func requestLogger(e echo.Context) zerolog.Logger {
logCtx := log.With().Str("remoteAddr", e.RealIP()) logCtx := log.With().
Str("remoteAddr", e.RealIP()).
Str("userAgent", e.Request().UserAgent())
worker := requestWorker(e) worker := requestWorker(e)
if worker != nil { if worker != nil {