mg-transport-core/core/logger/attrs.go

30 lines
647 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: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:20:04 +03:00
func HTTPStatus(code int) []any {
return []any{slog.Int(HTTPStatusAttr, code), slog.String(HTTPStatusNameAttr, http.StatusText(code))}
2023-10-18 15:19:01 +03:00
}