mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-26 07:06:03 +03:00
35 lines
742 B
Go
35 lines
742 B
Go
package logger
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
HandlerAttr = "handler"
|
|
ConnectionAttr = "connection"
|
|
AccountAttr = "account"
|
|
CounterIDAttr = "counterId"
|
|
ErrorAttr = "error"
|
|
FailureMessageAttr = "failureMessage"
|
|
BodyAttr = "body"
|
|
HTTPMethodAttr = "httpMethod"
|
|
HTTPStatusAttr = "httpStatusCode"
|
|
HTTPStatusNameAttr = "httpStatusName"
|
|
)
|
|
|
|
func ErrAttr(err any) slog.Attr {
|
|
if err == nil {
|
|
return slog.String(ErrorAttr, "<nil>")
|
|
}
|
|
return slog.Any(ErrorAttr, err)
|
|
}
|
|
|
|
func HTTPStatus(code int) []any {
|
|
return []any{slog.Int(HTTPStatusAttr, code), slog.String(HTTPStatusNameAttr, http.StatusText(code))}
|
|
}
|
|
|
|
func Body(val any) slog.Attr {
|
|
return slog.Any(BodyAttr, val)
|
|
}
|