MCPcopy
hub / github.com/caddyserver/caddy / errLogValues

Function errLogValues

modules/caddyhttp/logging.go:206–232  ·  view source on GitHub ↗

errLogValues inspects err and returns the status code to use, the error log message, and any extra fields. If err is a HandlerError, the returned values will have richer information.

(err error)

Source from the content-addressed store, hash-verified

204// If err is a HandlerError, the returned values will
205// have richer information.
206func errLogValues(err error) (status int, msg string, fields func() []zapcore.Field) {
207 var handlerErr HandlerError
208 if errors.As(err, &handlerErr) {
209 status = handlerErr.StatusCode
210 if handlerErr.Err == nil {
211 msg = err.Error()
212 } else {
213 msg = handlerErr.Err.Error()
214 }
215 fields = func() []zapcore.Field {
216 return []zapcore.Field{
217 zap.Int("status", handlerErr.StatusCode),
218 zap.String("err_id", handlerErr.ID),
219 zap.String("err_trace", handlerErr.Trace),
220 }
221 }
222 return status, msg, fields
223 }
224 fields = func() []zapcore.Field {
225 return []zapcore.Field{
226 zap.Error(err),
227 }
228 }
229 status = http.StatusInternalServerError
230 msg = err.Error()
231 return status, msg, fields
232}
233
234// ExtraLogFields is a list of extra fields to log with every request.
235type ExtraLogFields struct {

Callers 1

ServeHTTPMethod · 0.85

Calls 3

ErrorMethod · 0.45
IntMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected