katip-wai-0.2.0.0: WAI middleware for logging request and response info through katip.
Safe HaskellNone
LanguageHaskell2010

Katip.Wai.Options

Synopsis

Formatting

type Formatter a = a -> Value Source #

A formatter is a function that can convert a into json.

data TimeUnit Source #

Unit of time to use when logging response times.

type IncludedHeaders = Set HeaderName Source #

Headers to include in your logs.

defaultIncludedHeaders :: IncludedHeaders Source #

Default list of headers to include in logs: Host, Referer, 'User-Agent', and Range.

defaultRequestFormat :: IncludedHeaders -> Formatter Request Source #

Default formatter for Requests.

Example:

{
   "headers": {
     Host: "localhost:4000",
     Referer: "http://localhost:4000/docs/",
     "User-Agent": "Mozilla5.0 (X11; Linux x86_64; rv:130.0) Gecko20100101 Firefox/130.0"
   },
   "httpVersion": "HTTP/1.1",
   "id": "299b188e-f695-49ee-a92f-9078a29f2ec4",
   "isSecure": false,
   "method": GET,
   "path": "/openapi.json",
   "queryString": [],
   "receivedAt": "2024-09-07T18:22:50.943042066Z",
   "remoteHost": "127.0.0.1:58046"
 }

defaultResponseFormat :: IncludedHeaders -> TimeUnit -> Formatter Response Source #

Default formatter for Responses.

Example:

{
   "headers": {},
   "respondedAt": "2024-09-07T18:22:50.943213512Z",
   "responseTime": {
     "time": 0.167463,
     "unit": "ms"
   },
   "status": {
     "code": 200,
     "message": OK
   }
 }

Options

data Options (m :: Type -> Type) Source #

Options to customize how to handle the Request and Response.

You can use Monoid to combine Options:

mconcat
  [ addRequestAndResponseToContext
      requestFormatter
      responseFormatter
  , logRequestAndResponse severity
  ]

Constructors

Options 

Fields

Instances

Instances details
Monoid (Options m) Source # 
Instance details

Defined in Katip.Wai.Options

Methods

mempty :: Options m #

mappend :: Options m -> Options m -> Options m #

mconcat :: [Options m] -> Options m #

Semigroup (Options m) Source # 
Instance details

Defined in Katip.Wai.Options

Methods

(<>) :: Options m -> Options m -> Options m #

sconcat :: NonEmpty (Options m) -> Options m #

stimes :: Integral b => b -> Options m -> Options m #

addRequestAndResponseToContext :: forall (m :: Type -> Type). KatipContext m => Formatter Request -> Formatter Response -> Options m Source #

Add the Request to the LogContexts under "request", and add Response to the LogContext under "response".

logRequestAndResponse :: forall (m :: Type -> Type). KatipContext m => Severity -> Options m Source #

Log "Request received." when a request comes in, and log "Response sent." when a response is sent back.

options :: forall (m :: Type -> Type). KatipContext m => Formatter Request -> Formatter Response -> Severity -> Options m Source #

Combines addRequestAndResponseToContext and logRequestAndResponse with the formatters and severity you provide.