aboutsummaryrefslogtreecommitdiff
path: root/src/LogFormat.hs
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2016-06-13 15:48:13 +0800
committerIgor Pashev <pashev.igor@gmail.com>2016-06-14 04:02:31 +0800
commit76860ce667a40b69866241c1bf0b8ab76f50d1d2 (patch)
tree51b4ae1538bc0bf1effd0690081429ec508e010c /src/LogFormat.hs
downloadmywatch-76860ce667a40b69866241c1bf0b8ab76f50d1d2.tar.gz
Version 0.1.00.1.0
Diffstat (limited to 'src/LogFormat.hs')
-rw-r--r--src/LogFormat.hs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/LogFormat.hs b/src/LogFormat.hs
new file mode 100644
index 0000000..51c36c6
--- /dev/null
+++ b/src/LogFormat.hs
@@ -0,0 +1,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
+