mirror of
https://github.com/typeable/wai.git
synced 2025-01-06 05:25:53 +03:00
Move CPP logic into separate module for #192
This commit is contained in:
parent
747697e28b
commit
fb6bf738d3
@ -1,6 +1,8 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
-- NOTE: Due to https://github.com/yesodweb/wai/issues/192, this module should
|
||||
-- not use CPP.
|
||||
module Network.Wai.Middleware.RequestLogger
|
||||
( -- * Basic stdout logging
|
||||
logStdout
|
||||
@ -39,11 +41,7 @@ import System.IO.Unsafe
|
||||
|
||||
import Data.Default (Default (def))
|
||||
import Network.Wai.Logger.Format (apacheFormat, IPAddrSource (..))
|
||||
#if MIN_VERSION_fast_logger(0,3,0)
|
||||
import System.Date.Cache (ondemandDateCacher)
|
||||
#else
|
||||
import System.Log.FastLogger.Date (getDate, dateInit, ZonedDate)
|
||||
#endif
|
||||
import Network.Wai.Middleware.RequestLogger.Internal
|
||||
|
||||
data OutputFormat = Apache IPAddrSource
|
||||
| Detailed Bool -- ^ use colors?
|
||||
@ -96,13 +94,7 @@ mkRequestLogger RequestLoggerSettings{..} = do
|
||||
dateHelper mgetdate = do
|
||||
case mgetdate of
|
||||
Just x -> return x
|
||||
#if MIN_VERSION_fast_logger(0, 3, 0)
|
||||
Nothing -> do
|
||||
(getter,_) <- ondemandDateCacher zonedDateCacheConf
|
||||
return getter
|
||||
#else
|
||||
Nothing -> fmap getDate dateInit
|
||||
#endif
|
||||
Nothing -> getDateGetter
|
||||
|
||||
apacheMiddleware :: Callback -> IPAddrSource -> IO ZonedDate -> Middleware
|
||||
apacheMiddleware cb ipsrc getdate = customMiddleware cb getdate $ apacheFormat ipsrc
|
||||
|
20
wai-extra/Network/Wai/Middleware/RequestLogger/Internal.hs
Normal file
20
wai-extra/Network/Wai/Middleware/RequestLogger/Internal.hs
Normal file
@ -0,0 +1,20 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
-- | A module for containing some CPPed code, due to:
|
||||
--
|
||||
-- https://github.com/yesodweb/wai/issues/192
|
||||
module Network.Wai.Middleware.RequestLogger.Internal where
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
import System.Log.FastLogger
|
||||
#if MIN_VERSION_fast_logger(0,3,0)
|
||||
import System.Date.Cache (ondemandDateCacher)
|
||||
#else
|
||||
import System.Log.FastLogger.Date (getDate, dateInit, ZonedDate)
|
||||
#endif
|
||||
|
||||
getDateGetter :: IO (IO ByteString)
|
||||
#if MIN_VERSION_fast_logger(0, 3, 0)
|
||||
getDateGetter = fmap fst $ ondemandDateCacher zonedDateCacheConf
|
||||
#else
|
||||
getDateGetter = fmap getDate dateInit
|
||||
#endif
|
@ -61,6 +61,7 @@ Library
|
||||
Network.Wai.Middleware.Vhost
|
||||
Network.Wai.Middleware.HttpAuth
|
||||
Network.Wai.Parse
|
||||
other-modules: Network.Wai.Middleware.RequestLogger.Internal
|
||||
ghc-options: -Wall
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user