Apache style logger.
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 pongSynopsis
- type ApacheLogger
- value withStdoutLogger
- type ServerPushLogger
- data ApacheLoggerActions
- value apacheLogger
- value serverpushLogger
- value logRotator
- value logRemover
- value initLoggerUser
- value initLogger
- data IPAddrSource
- data LogType'
- type LogType
- data FileLogSpec
- value showSockAddr
- value logCheck
- value clockDateCacher
- type ZonedDate
- type DateCacheGetter
- type DateCacheUpdater
- Packagewai-logger-2.5.0
- Exports20
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceLogger.hs
High level functions
Executing a function which takes ApacheLogger. This ApacheLogger writes log message to stdout. Each buffer (4K bytes) is flushed every second.
HTTP/2 server push logger in Apache style.
Creating a logger
Function set of Apache style logger.
The Apache logger.
The HTTP/2 server push logger.
This is obsoleted. Rotation is done on-demand. So, this is now an empty action.
Removing resources relating to Apache logger. E.g. flushing and deallocating internal buffers.
Creating ApacheLogger according to LogType.
Types
Source from which the IP source address of the client is obtained.
Constructors
FromSocketFrom the peer address of the HTTP connection.
FromHeaderFrom
X-Real-IPorX-Forwarded-Forin the HTTP header.This picks either
X-Real-IPorX-Forwarded-Fordepending on which of these headers comes first in the ordered list of request headers.If the
X-Forwarded-Forheader 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.
FromFallbackJust 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.
Logger Type.
Constructors
LogNone :: LogType' LogStrLogStdout :: BufSize -> LogType' LogStrLogStderr :: BufSize -> LogType' LogStrLogFileNoRotate :: FilePath -> BufSize -> LogType' LogStrLogFile :: FileLogSpec -> BufSize -> LogType' LogStrLogFileTimedRotate :: TimedFileLogSpec -> BufSize -> LogType' LogStrLogCallback :: (v -> IO ()) -> IO () -> LogType' a
The spec for logging files
Constructors
FileLogSpeclog_file :: FilePathlog_file_size :: IntegerMax log file size (in bytes) before requiring rotation.
log_backup_number :: IntMax number of rotated log files to keep around before overwriting the oldest one.
Utilities
Convert SockAddr to NumericAddress. If the address is
IPv4-embedded IPv6 address, the IPv4 is extracted.
Backward compability
Returning DateCacheGetter and DateCacheUpdater.
Note: Since version 2.1.2, this function uses the auto-update package
internally, and therefore the DateCacheUpdater value returned need
not be called. To wit, the return value is in fact an empty action.
A type for zoned date.
Getting cached ZonedDate.
Updateing cached ZonedDate. This should be called every second. See the source code of withStdoutLogger.