{-# LANGUAGE OverloadedStrings #-}moduleNetwork.Wai.Middleware.RequestLogger(logStdout,logHandle,logStdoutDev,logHandleDev,logStdoutDevLT,logHandleDevLT)whereimportSystem.IO(stdout)importqualifiedData.ByteStringasBSimportData.ByteString.Char8(pack)importControl.Monad.IO.Class(liftIO)importNetwork.Wai(Request(..),Middleware)importSystem.Log.FastLoggerimportNetwork.HTTP.TypesasHimportqualifiedData.Text.LazyasLTimportqualifiedData.Text.EncodingasTEimportNetwork.Wai.Parse(parseRequestBody,lbsSink,fileName,Param,File)importqualifiedData.ByteString.LazyasLBSimportData.Enumerator(run_,($$),enumList)importData.Enumerator.List(consume)importSystem.IO(hPutStrLn,stderr)-- | like @logHandle@, but prints to 'stdout'logStdout::MiddlewarelogStdout=logHandle$\bs->hPutLogStrstdout[LBbs]-- | like @logHandleDev@, but prints to 'stdout'logStdoutDev::MiddlewarelogStdoutDev=logHandleDev$\bs->hPutLogStrstdout[LBbs]-- | Prints a message using the given callback function for each request.-- Designed for fast production use at the expense of convenience.-- In particular, no POST parameter information is currently given-- For something with more useful output, use Network.Wai.Middleware.DebuglogHandle::(BS.ByteString->IO())->MiddlewarelogHandlecbappreq=doliftIO$cb$BS.concat[requestMethodreq," ",rawPathInforeq,rawQueryStringreq," ","Accept: ",maybe""toBS$lookup"Accept"$requestHeadersreq]appreqtoBS::H.Ascii->BS.ByteStringtoBS=id-- | Inefficient, but convenient Development load logger middleware-- Prints a message to 'stderr' for each request using logHandleDevLTlogStdoutDevLT::MiddlewarelogStdoutDevLT=logHandleDevLT$hPutStrLnstderr.LT.unpack-- | logHandleDev, but expects Lazy Text instead of a ByteStringlogHandleDevLT::(LT.Text->IO())->MiddlewarelogHandleDevLTcbappreq=logHandleDev(\msg->cb$LT.fromStrict$TE.decodeUtf8msg)appreq-- | Prints a message using the given callback function for each request.-- This is not for serious production use- it is inefficient.-- It immediately consumes a POST body and fills it back in and is otherwise inefficient-- For production use use module Network.Wai.Middleware.RequestLoggerlogHandleDev::(BS.ByteString->IO())->MiddlewarelogHandleDevcbappreq=dobody<-consumepostParams<-ifany(requestMethodreq==)["GET","HEAD"]thenreturn[]elsedopostParams<-liftIO$allPostParamsreqbodyreturn$collectPostParamspostParamsletgetParams=mapemptyGetParam$queryStringreqliftIO$cb$BS.concat[requestMethodreq," ",rawPathInforeq,"\n","Accept: ",maybe""id$lookup"Accept"$requestHeadersreq,paramsToBS"GET "getParams,paramsToBS"POST "postParams]-- we just consumed the body- fill the enumerator back up so it is available againliftIO$run_$enumList1body$$appreqwhereparamsToBSprefixparams=ifnullparamsthen""elseBS.concat["\n",prefix,pack(showparams)]allPostParamsreq'body=run_$enumList1body$$parseRequestBodylbsSinkreq'emptyGetParam::(BS.ByteString,MaybeBS.ByteString)->(BS.ByteString,BS.ByteString)emptyGetParam(k,Justv)=(k,v)emptyGetParam(k,Nothing)=(k,"")collectPostParams::([Param],[FileLBS.ByteString])->[Param]collectPostParams(postParams,files)=postParams++(map(\(k,v)->(k,BS.append"FILE: "(fileNamev)))files)