39 lines
795 B
Go
Raw Normal View History

2023-10-18 14:27:23 +03:00
package logger
2023-10-18 15:19:01 +03:00
import (
"log/slog"
"net/http"
)
2023-10-18 14:27:23 +03:00
const (
HandlerAttr = "handler"
ConnectionAttr = "connection"
AccountAttr = "account"
CounterIDAttr = "counterId"
ErrorAttr = "error"
FailureMessageAttr = "failureMessage"
2023-10-18 15:30:01 +03:00
BodyAttr = "body"
2023-10-18 15:16:00 +03:00
HTTPMethodAttr = "httpMethod"
HTTPStatusAttr = "httpStatusCode"
HTTPStatusNameAttr = "httpStatusName"
2023-10-18 14:27:23 +03:00
)
func ErrAttr(err any) slog.Attr {
if err == nil {
return slog.String(ErrorAttr, "<nil>")
}
return slog.Any(ErrorAttr, err)
}
2023-10-18 15:19:01 +03:00
2023-10-18 15:36:55 +03:00
func HTTPStatusCode(code int) slog.Attr {
return slog.Int(HTTPStatusAttr, code)
}
func HTTPStatusName(code int) slog.Attr {
return slog.String(HTTPStatusNameAttr, http.StatusText(code))
2023-10-18 15:19:01 +03:00
}
2023-10-18 15:30:01 +03:00
func Body(val any) slog.Attr {
return slog.Any(BodyAttr, val)
}