Move CPP logic into separate module for #192

This commit is contained in:
Michael Snoyman 2013-11-04 11:06:32 +02:00
parent 747697e28b
commit fb6bf738d3
3 changed files with 26 additions and 13 deletions

View File

@ -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

View 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

View File

@ -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