Safe Haskell | None |
---|---|
Language | Haskell2010 |
Servant.Util.Combinators.Logging
Contents
Description
Allows to enable logging of requests and responses.
Synopsis
- data LoggingApi config api
- data LoggingApiRec config api
- class HasServer api ctx => HasLoggingServer config api ctx where
- routeWithLog :: Proxy (LoggingApiRec config api) -> Context ctx -> Delayed env (Server (LoggingApiRec config api)) -> Router env
- newtype ServantLogConfig = ServantLogConfig {}
- newtype ForResponseLog a = ForResponseLog {
- unForResponseLog :: a
- buildListForResponse :: Buildable (ForResponseLog x) => (forall a. [a] -> [a]) -> ForResponseLog [x] -> Builder
- buildForResponse :: Buildable a => ForResponseLog a -> Builder
- class ApiHasArgClass api where
- type ApiArg api :: Type
- apiArgName :: Proxy api -> String
- class ApiHasArgClass subApi => ApiCanLogArg subApi where
- type ApiArgToLog subApi :: Type
- toLogParamInfo :: Buildable (ApiArgToLog subApi) => Proxy subApi -> ApiArg subApi -> Text
- addParamLogInfo :: Text -> ApiParamsLogInfo -> ApiParamsLogInfo
- setInPrefix :: ApiParamsLogInfo -> ApiParamsLogInfo
- serverWithLogging :: forall api a. ServantLogConfig -> Proxy api -> (forall (config :: Type). Reifies config ServantLogConfig => Proxy (LoggingApi config api) -> a) -> a
Automatic requests logging
data LoggingApi config api Source #
Enables logging for server which serves given api.
config
is a type at which you have to specify ServantLogConfig
via
reflection. This way was chosen because the least thing we need in
config is LoggerName
, and we want to have <>
on LoggerName
s thus
KnownSymbol
is not enough.
This logging will report
- Request parameters, including request bodies
- If execution failed with error, it will be displayed
- Details like request method and endpoint execution time
If user makes request which is not defined it won't be logged. However, I don't find it a great problem, it may impede only in development or on getting acknowledged with api.
Instances
(HasServer (LoggingApiRec config api) ctx, HasServer api ctx) => HasServer (LoggingApi config api :: Type) ctx Source # | |
Defined in Servant.Util.Combinators.Logging Associated Types type ServerT (LoggingApi config api) m # Methods route :: Proxy (LoggingApi config api) -> Context ctx -> Delayed env (Server (LoggingApi config api)) -> Router env # hoistServerWithContext :: Proxy (LoggingApi config api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (LoggingApi config api) m -> ServerT (LoggingApi config api) n # | |
type ServerT (LoggingApi config api :: Type) m Source # | |
Defined in Servant.Util.Combinators.Logging |
data LoggingApiRec config api Source #
Helper to traverse servant api and apply logging.
Instances
HasLoggingServer config api ctx => HasServer (LoggingApiRec config api :: Type) ctx Source # | |
Defined in Servant.Util.Combinators.Logging Associated Types type ServerT (LoggingApiRec config api) m # Methods route :: Proxy (LoggingApiRec config api) -> Context ctx -> Delayed env (Server (LoggingApiRec config api)) -> Router env # hoistServerWithContext :: Proxy (LoggingApiRec config api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (LoggingApiRec config api) m -> ServerT (LoggingApiRec config api) n # | |
type ServerT (LoggingApiRec config api :: Type) m Source # | |
Defined in Servant.Util.Combinators.Logging |
class HasServer api ctx => HasLoggingServer config api ctx where Source #
Version of HasServer
which is assumed to perform logging.
It's helpful because 'ServerT (LoggingApi ...)' is already defined for us
in actual HasServer
instance once and forever.
Methods
routeWithLog :: Proxy (LoggingApiRec config api) -> Context ctx -> Delayed env (Server (LoggingApiRec config api)) -> Router env Source #
Instances
newtype ServantLogConfig Source #
Constructors
ServantLogConfig | |
newtype ForResponseLog a Source #
When it comes to logging responses, returned data may be very large. Log space is valuable (already in testnet we got truncated logs), so we have to care about printing only whose data which may be useful.
Constructors
ForResponseLog | |
Fields
|
Instances
Buildable (ForResponseLog Integer) Source # | |
Defined in Servant.Util.Combinators.Logging Methods build :: ForResponseLog Integer -> Builder # | |
Buildable (ForResponseLog ()) Source # | |
Defined in Servant.Util.Combinators.Logging Methods build :: ForResponseLog () -> Builder # | |
Buildable (ForResponseLog NoContent) Source # | |
Defined in Servant.Util.Combinators.Logging Methods build :: ForResponseLog NoContent -> Builder # | |
Buildable (ForResponseLog Swagger) Source # | |
Defined in Servant.Util.Combinators.Logging Methods build :: ForResponseLog Swagger -> Builder # | |
Buildable (ForResponseLog (SwaggerUiHtml dir api)) Source # | |
Defined in Servant.Util.Combinators.Logging Methods build :: ForResponseLog (SwaggerUiHtml dir api) -> Builder # |
buildListForResponse :: Buildable (ForResponseLog x) => (forall a. [a] -> [a]) -> ForResponseLog [x] -> Builder Source #
buildForResponse :: Buildable a => ForResponseLog a -> Builder Source #
class ApiHasArgClass api where Source #
Proves info about argument specifier of servant API.
Minimal complete definition
Nothing
Associated Types
type ApiArg api :: Type Source #
For arguments-specifiers of API, get argument type.
E.g. Capture "cap" Int
-> Int
.
type ApiArg api = ApplicationRS api
Methods
apiArgName :: Proxy api -> String Source #
Name of argument.
E.g. name of argument specified by Capture "nyan"
is nyan.
default apiArgName :: forall n someApiType a. (KnownSymbol n, api ~ someApiType n a) => Proxy api -> String Source #
Instances
KnownSymbol s => ApiHasArgClass (QueryFlag s) Source # | |
ApiHasArgClass (ReqBody ct a) Source # | |
KnownSymbol s => ApiHasArgClass (Capture s a) Source # | |
KnownSymbol s => ApiHasArgClass (QueryParam' mods s a) Source # | |
Defined in Servant.Util.Common.Common Associated Types type ApiArg (QueryParam' mods s a) Source # Methods apiArgName :: Proxy (QueryParam' mods s a) -> String Source # |
class ApiHasArgClass subApi => ApiCanLogArg subApi where Source #
Describes a way to log a single parameter.
Minimal complete definition
Nothing
Methods
toLogParamInfo :: Buildable (ApiArgToLog subApi) => Proxy subApi -> ApiArg subApi -> Text Source #
Instances
KnownSymbol cs => ApiCanLogArg (QueryFlag cs) Source # | |
Defined in Servant.Util.Combinators.Logging Associated Types type ApiArgToLog (QueryFlag cs) Source # | |
ApiCanLogArg (ReqBody ct a) Source # | |
Defined in Servant.Util.Combinators.Logging Associated Types type ApiArgToLog (ReqBody ct a) Source # | |
KnownSymbol s => ApiCanLogArg (Capture s a) Source # | |
Defined in Servant.Util.Combinators.Logging Associated Types type ApiArgToLog (Capture s a) Source # | |
(Buildable a, KnownSymbol cs, SBoolI (FoldRequired mods)) => ApiCanLogArg (QueryParam' mods cs a) Source # | |
Defined in Servant.Util.Combinators.Logging Associated Types type ApiArgToLog (QueryParam' mods cs a) Source # Methods toLogParamInfo :: Proxy (QueryParam' mods cs a) -> ApiArg (QueryParam' mods cs a) -> Text Source # |
addParamLogInfo :: Text -> ApiParamsLogInfo -> ApiParamsLogInfo Source #
setInPrefix :: ApiParamsLogInfo -> ApiParamsLogInfo Source #
serverWithLogging :: forall api a. ServantLogConfig -> Proxy api -> (forall (config :: Type). Reifies config ServantLogConfig => Proxy (LoggingApi config api) -> a) -> a Source #
Apply logging to the given server.