@@ -12,6 +12,7 @@ module Network.Wai.Middleware.RequestLogger
12 , autoFlush
12 , autoFlush
13 , destination
13 , destination
14 , OutputFormat (..)
14 , OutputFormat (..)
15 , Destination (..)
16 , Destination (..)
16 , Callback
17 , Callback
17 , IPAddrSource (..)
18 , IPAddrSource (..)
@@ -46,6 +47,9 @@ import System.Log.FastLogger.Date (getDate, dateInit, ZonedDate)
47data OutputFormat = Apache IPAddrSource
48data OutputFormat = Apache IPAddrSource
48 | Detailed Bool -- ^ use colors?
49 | Detailed Bool -- ^ use colors?
50+ | CustomOutputFormat OutputFormatter
52+type OutputFormatter = ZonedDate -> Request -> Status -> Maybe Integer -> [LogStr]
50data Destination = Handle Handle
54data Destination = Handle Handle
51 | Logger Logger
55 | Logger Logger
@@ -81,27 +85,34 @@ mkRequestLogger RequestLoggerSettings{..} = do
81 Callback c -> return (c, Nothing)
85 Callback c -> return (c, Nothing)
82 case outputFormat of
86 case outputFormat of
83 Apache ipsrc -> do
87 Apache ipsrc -> do
84− getdate <-
88+ getdate <- dateHelper mgetdate
87−#if MIN_VERSION_fast_logger(0, 3, 0)
89− (getter,_) <- ondemandDateCacher zonedDateCacheConf
92− Nothing -> fmap getDate dateInit
94 return $ apacheMiddleware callback ipsrc getdate
89 return $ apacheMiddleware callback ipsrc getdate
95 Detailed useColors -> detailedMiddleware callback useColors
90 Detailed useColors -> detailedMiddleware callback useColors
91+ CustomOutputFormat formatter -> do
92+ getdate <- dateHelper mgetdate
93+ return $ customMiddleware callback getdate formatter
97 fromLogger l = (loggerPutStr l, Just $ loggerDate l)
95 fromLogger l = (loggerPutStr l, Just $ loggerDate l)
96+ dateHelper mgetdate = do
99+#if MIN_VERSION_fast_logger(0, 3, 0)
101+ (getter,_) <- ondemandDateCacher zonedDateCacheConf
104+ Nothing -> fmap getDate dateInit
99apacheMiddleware :: Callback -> IPAddrSource -> IO ZonedDate -> Middleware
107apacheMiddleware :: Callback -> IPAddrSource -> IO ZonedDate -> Middleware
100−apacheMiddleware cb ipsrc getdate app req = do
108+apacheMiddleware cb ipsrc getdate = customMiddleware cb getdate $ apacheFormat ipsrc
110+customMiddleware :: Callback -> IO ZonedDate -> OutputFormatter -> Middleware
111+customMiddleware cb getdate formatter app req = do
101 res <- app req
112 res <- app req
102 date <- liftIO getdate
113 date <- liftIO getdate
103 -- We use Nothing for the response size since we generally don't know it
114 -- We use Nothing for the response size since we generally don't know it
104− liftIO $ cb $ apacheFormat ipsrc date req (responseStatus res) Nothing
115+ liftIO $ cb $ formatter date req (responseStatus res) Nothing
105 return res
116 return res
107-- | Production request logger middleware.
118-- | Production request logger middleware.