blob: 51c36c6ed048007f3bca393fc9870d81e0f6d9ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
{-# LANGUAGE OverloadedStrings #-}
module LogFormat (
logFormat
) where
import Data.Maybe (fromMaybe)
import Data.Monoid ((<>))
import Network.HTTP.Types (Status(statusCode))
import Network.Wai (Request, httpVersion, requestHeaders, requestMethod,
rawPathInfo, requestHeaderReferer, requestHeaderUserAgent)
import System.Log.FastLogger (LogStr, toLogStr)
import qualified Data.ByteString.Char8 as BS
-- Sligthly modified Common Log Format.
-- User ID extracted from the From header.
logFormat :: BS.ByteString -> Request -> Status -> Maybe Integer -> LogStr
logFormat t req st msize = ""
<> toLogStr (fromMaybe "-" $ lookup "X-Forwarded-For" headers)
<> " - "
<> toLogStr (fromMaybe "-" $ lookup "From" headers)
<> " ["
<> toLogStr t
<> "] \""
<> toLogStr (requestMethod req)
<> " "
<> toLogStr (rawPathInfo req)
<> " "
<> toLogStr (show $ httpVersion req)
<> "\" "
<> toLogStr (show $ statusCode st)
<> " "
<> toLogStr (maybe "-" show msize)
<> " \""
<> toLogStr (fromMaybe "" $ requestHeaderReferer req)
<> "\" \""
<> toLogStr (fromMaybe "" $ requestHeaderUserAgent req)
<> "\"\n"
where headers = requestHeaders req
|