danielgtaylor / danielgtaylor/huma

Logging Errors in Huma Middleware

Open
#679 4 comments 4 reactions 0 assignees View on GitHub
question
Dominant language
Go
Stars
4.4k
Forks
285
Avg merge
40m
Merged PRs (30d)
1

Description

I am currently working on a Huma middleware and need assistance with logging errors. Specifically, I would like to log the following:

1. Input structure
2. Output errors or the entire output structure

Although I managed to log HTTP status responses, I have not found a proper way to log input parameters and output errors. Here is the current code snippet I am using:

```go
package middleware

import (
"my/logging"
"github.com/danielgtaylor/huma/v2"
)

func HumaTracing(ctx huma.Context, next func(huma.Context)) {
// Call the next middleware or handler
next(ctx)

// Inspect the response for errors
if ctx.Status() >= 400 {
log := logging.Logger(ctx.Context())
log.Error("Handler error", "status", ctx.Status())
}
}
```

Is there a general way to configure comprehensive logging in a Huma application, including input parameters and output errors?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.