wai-extra-3.0.29.2: Provides some basic WAI handlers and middleware.

Safe Haskell | None
Language | Haskell2010

Network.Wai.Middleware.RequestLogger

Contents

- Basic stdout logging
- Create more versions

Synopsis

- logStdout :: Middleware
- logStdoutDev :: Middleware
- mkRequestLogger :: RequestLoggerSettings -> IO Middleware
- data RequestLoggerSettings
- outputFormat :: RequestLoggerSettings -> OutputFormat
- autoFlush :: RequestLoggerSettings -> Bool
- destination :: RequestLoggerSettings -> Destination
- data OutputFormat
  - = Apache IPAddrSource
  - | Detailed Bool
  - | CustomOutputFormat OutputFormatter
  - | CustomOutputFormatWithDetails OutputFormatterWithDetails
  - | CustomOutputFormatWithDetailsAndHeaders OutputFormatterWithDetailsAndHeaders
- type OutputFormatter = ZonedDate -> Request -> Status -> Maybe Integer -> LogStr
- type OutputFormatterWithDetails = ZonedDate -> Request -> Status -> Maybe Integer -> NominalDiffTime -> [ByteString] -> Builder -> LogStr
- type OutputFormatterWithDetailsAndHeaders = ZonedDate -> Request -> Status -> Maybe Integer -> NominalDiffTime -> [ByteString] -> Builder -> [Header] -> LogStr
- data Destination
  - = Handle Handle
  - | Logger LoggerSet
  - | Callback Callback
- type Callback = LogStr -> IO ()
- data IPAddrSource
  - = FromSocket
  - | FromHeader
  - | FromFallback

# Basic stdout logging

logStdout :: Middleware Source #

Production request logger middleware.

This uses the `Apache` logging format, and takes IP addresses for clients from the socket (see `IPAddrSource` for more information). It logs to `stdout`.

logStdoutDev :: Middleware Source #

Development request logger middleware.

This uses the `Detailed` `True` logging format and logs to `stdout`.

# Create more versions

mkRequestLogger :: RequestLoggerSettings -> IO Middleware Source #

data RequestLoggerSettings Source #

`RequestLoggerSettings` is an instance of Default. See Data.Default for more information.

`outputFormat`, `autoFlush`, and `destination` are record fields for the record type `RequestLoggerSettings`, so they can be used to modify settings values using record syntax.

#### Instances

Instances details

Default RequestLoggerSettings Source # |
Instance details Defined in Network.Wai.Middleware.RequestLogger Methods def :: RequestLoggerSettings Source #

outputFormat :: RequestLoggerSettings -> OutputFormat Source #

Default value: `Detailed` `True`.

autoFlush :: RequestLoggerSettings -> Bool Source #

Only applies when using the `Handle` constructor for `destination`.

Default value: `True`.

destination :: RequestLoggerSettings -> Destination Source #

Default: `Handle` `stdout`.

data OutputFormat Source #

Constructors

Apache IPAddrSource |
Detailed Bool | use colors?
CustomOutputFormat OutputFormatter |
CustomOutputFormatWithDetails OutputFormatterWithDetails |
CustomOutputFormatWithDetailsAndHeaders OutputFormatterWithDetailsAndHeaders |

type OutputFormatter = ZonedDate -> Request -> Status -> Maybe Integer -> LogStr Source #

type OutputFormatterWithDetails = ZonedDate -> Request -> Status -> Maybe Integer -> NominalDiffTime -> [ByteString] -> Builder -> LogStr Source #

type OutputFormatterWithDetailsAndHeaders Source #

Arguments

= ZonedDate | When the log message was generated
-> Request | The WAI request
-> Status | HTTP status code
-> Maybe Integer | Response size
-> NominalDiffTime | Duration of the request
-> [ByteString] | The request body
-> Builder | Raw response
-> [Header] | The response headers
-> LogStr |

Same as `OutputFormatterWithDetails` but with response headers included

This is useful if you wish to include arbitrary application data in your logs, e.g., an authenticated user ID, which you would set in a response header in your application and retrieve in the log formatter.

Since: 3.0.27

data Destination Source #

Constructors

Handle Handle |
Logger LoggerSet |
Callback Callback |

type Callback = LogStr -> IO () Source #

data IPAddrSource Source #

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.
FromFallback | From the peer address if header is not found.