Safe Haskell | None |
---|---|
Language | Haskell2010 |
Allows to enable logging of requests and responses.
Synopsis
- data LoggingApi config api
- data LoggingApiRec config (lcontext :: LoggingContext) api
- data LoggingMod (mod :: LoggingModKind)
- type LoggingLevel lvl = LoggingMod ('LMLoggingLevel lvl)
- type LoggingRequestsEnabled = LoggingMod ('LMRequestsLogged 'True)
- type LoggingRequestsDisabled = LoggingMod ('LMRequestsLogged 'False)
- type LoggingResponsesEnabled = LoggingMod ('LMResponsesLogged 'True)
- type LoggingResponsesDisabled = LoggingMod ('LMResponsesLogged 'False)
- type LoggingDisabled = LoggingMod 'LMLoggingDisabled
- newtype LogContext = LogContext {}
- class HasServer api ctx => HasLoggingServer config (lcontext :: LoggingContext) api ctx where
- routeWithLog :: Proxy (LoggingApiRec config lcontext api) -> Context ctx -> Delayed env (Server (LoggingApiRec config lcontext api)) -> Router env
- newtype ServantLogConfig = ServantLogConfig {
- clcLog :: LogContext -> Text -> IO ()
- newtype ForResponseLog a = ForResponseLog {
- unForResponseLog :: a
- type BuildableForResponseIfNecessary lcontext resp = (If (LcResponsesEnabled lcontext) (Buildable (ForResponseLog resp)) (() :: Constraint), Demote (LcResponsesEnabled lcontext))
- 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 EmptyLoggingContext api) ctx, HasServer api ctx) => HasServer (LoggingApi config api :: Type) ctx Source # | |
Defined in Servant.Util.Combinators.Logging type ServerT (LoggingApi config api) m # 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 (lcontext :: LoggingContext) api Source #
Helper to traverse servant api and apply logging.
Instances
HasLoggingServer config lcontext api ctx => HasServer (LoggingApiRec config lcontext api :: Type) ctx Source # | |
Defined in Servant.Util.Combinators.Logging type ServerT (LoggingApiRec config lcontext api) m # route :: Proxy (LoggingApiRec config lcontext api) -> Context ctx -> Delayed env (Server (LoggingApiRec config lcontext api)) -> Router env # hoistServerWithContext :: Proxy (LoggingApiRec config lcontext api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (LoggingApiRec config lcontext api) m -> ServerT (LoggingApiRec config lcontext api) n # | |
type ServerT (LoggingApiRec config lcontext api :: Type) m Source # | |
Defined in Servant.Util.Combinators.Logging |
data LoggingMod (mod :: LoggingModKind) Source #
Servant combinator that changes how the logs will be printed for the affected endpoints.
This is an internal thing, we export aliases.
Instances
type LoggingLevel lvl = LoggingMod ('LMLoggingLevel lvl) Source #
Combinator to set the logging level within the endpoints.
type LoggingRequestsEnabled = LoggingMod ('LMRequestsLogged 'True) Source #
Combinator to enable logging of requests back for a narrower set of entrypoints.
type LoggingRequestsDisabled = LoggingMod ('LMRequestsLogged 'False) Source #
Combinator to disable logging of requests.
type LoggingResponsesEnabled = LoggingMod ('LMResponsesLogged 'True) Source #
Combinator to enable logging of responses.
type LoggingResponsesDisabled = LoggingMod ('LMResponsesLogged 'False) Source #
Combinator to disable logging of responses.
type LoggingDisabled = LoggingMod 'LMLoggingDisabled Source #
Combinator to disable all the logging.
This works similarly to other similar combinators and can be partially
or fully reverted with LoggingRequestsDisabled
or LoggingResponsesDisabled
.
newtype LogContext Source #
Logging context that will be supplied to the user.
LogContext | |
|
Instances
Eq LogContext Source # | |
Defined in Servant.Util.Combinators.Logging (==) :: LogContext -> LogContext -> Bool # (/=) :: LogContext -> LogContext -> Bool # | |
Show LogContext Source # | |
Defined in Servant.Util.Combinators.Logging showsPrec :: Int -> LogContext -> ShowS # show :: LogContext -> String # showList :: [LogContext] -> ShowS # |
class HasServer api ctx => HasLoggingServer config (lcontext :: LoggingContext) 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.
routeWithLog :: Proxy (LoggingApiRec config lcontext api) -> Context ctx -> Delayed env (Server (LoggingApiRec config lcontext api)) -> Router env Source #
Instances
newtype ServantLogConfig Source #
Logging configuration specified at server start.
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.
Instances
Buildable (ForResponseLog Integer) Source # | |
Defined in Servant.Util.Combinators.Logging build :: ForResponseLog Integer -> Builder # | |
Buildable (ForResponseLog ()) Source # | |
Defined in Servant.Util.Combinators.Logging build :: ForResponseLog () -> Builder # | |
Buildable (ForResponseLog NoContent) Source # | |
Defined in Servant.Util.Combinators.Logging build :: ForResponseLog NoContent -> Builder # | |
Buildable (ForResponseLog Swagger) Source # | |
Defined in Servant.Util.Combinators.Logging build :: ForResponseLog Swagger -> Builder # | |
Buildable (ForResponseLog (SwaggerUiHtml dir api)) Source # | |
Defined in Servant.Util.Combinators.Logging build :: ForResponseLog (SwaggerUiHtml dir api) -> Builder # |
type BuildableForResponseIfNecessary lcontext resp = (If (LcResponsesEnabled lcontext) (Buildable (ForResponseLog resp)) (() :: Constraint), Demote (LcResponsesEnabled lcontext)) Source #
Require Buildable
for the response type, but only if logging context
assumes that the response will indeed be built.
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.
Nothing
type ApiArg api :: Type Source #
For arguments-specifiers of API, get argument type.
E.g. Capture "cap" Int
-> Int
.
type ApiArg api = ApplicationRS api
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 type ApiArg (QueryParam' mods s a) Source # apiArgName :: Proxy (QueryParam' mods s a) -> String Source # |
class ApiHasArgClass subApi => ApiCanLogArg subApi where Source #
Describes a way to log a single parameter.
Nothing
type ApiArgToLog subApi :: Type Source #
type ApiArgToLog subApi = ApiArg subApi
toLogParamInfo :: Buildable (ApiArgToLog subApi) => Proxy subApi -> ApiArg subApi -> Text Source #
Instances
KnownSymbol cs => ApiCanLogArg (QueryFlag cs) Source # | |
Defined in Servant.Util.Combinators.Logging type ApiArgToLog (QueryFlag cs) Source # | |
ApiCanLogArg (ReqBody ct a) Source # | |
Defined in Servant.Util.Combinators.Logging type ApiArgToLog (ReqBody ct a) Source # | |
KnownSymbol s => ApiCanLogArg (Capture s a) Source # | |
Defined in Servant.Util.Combinators.Logging 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 type ApiArgToLog (QueryParam' mods cs a) Source # 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.