HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulewai-logger-2.5.0Haskell2010

Network.Wai.Logger

Apache style logger for WAI applications.

An example:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Data.ByteString.Builder (byteString)
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString.Char8 as BS
import Network.HTTP.Types (status200)
import Network.Wai (Application, responseBuilder)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Logger (withStdoutLogger, ApacheLogger)

main :: IO ()
main = withStdoutLogger $ \aplogger ->
    run 3000 $ logApp aplogger

logApp :: ApacheLogger -> Application
logApp aplogger req response = do
    liftIO $ aplogger req status (Just len)
    response $ responseBuilder status hdr msg
  where
    status = status200
    hdr = [("Content-Type", "text/plain")]
    pong = "PONG"
    msg = byteString pong
    len = fromIntegral $ BS.length pong
  • 10 types
  • 10 values
  • Packagewai-logger-2.5.0
  • Exports20
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceLogger.hs

High level functions

3 declarations

Creating a logger

7 declarations

Types

4 declarations
datadata IPAddrSource
#

Source from which the IP source address of the client is obtained.

Constructors

  • FromSocket

    From the peer address of the HTTP connection.

  • FromHeader

    From X-Real-IP or X-Forwarded-For in the HTTP header.

    This picks either X-Real-IP or X-Forwarded-For depending on which of these headers comes first in the ordered list of request headers.

    If the X-Forwarded-For header is picked, the value will be assumed to be a comma-separated list of IP addresses. The value will be parsed, and the left-most IP address will be used (which is mostly likely to be the actual client IP address).

  • FromHeaderCustom [HeaderName]

    From a custom HTTP header, useful in proxied environment.

    The header value will be assumed to be a comma-separated list of IP addresses. The value will be parsed, and the left-most IP address will be used (which is mostly likely to be the actual client IP address).

    Note that this still works as expected for a single IP address.

  • FromFallback

    Just like FromHeader, but falls back on the peer address if header is not found.

  • FromRequest (Request -> ByteString)

    This gives you the most flexibility to figure out the IP source address from the Request. The returned ByteString is used as the IP source address.

Utilities

2 declarations
valueshowSockAddr :: SockAddr -> NumericAddress
#

Convert SockAddr to NumericAddress. If the address is IPv4-embedded IPv6 address, the IPv4 is extracted.

Backward compability

4 declarations