on master help sign in
logStdoutDev flushes
commit98e8a3ddfd41715b1a50666deecb52f3d73a0d4f authorMichael Snoyman <michael@snoyman.com> dateTue 17 Jan 2012, 08:43 (15 years ago) parent0b65c68
1 file changed+17−4
wai-extra/Network/Wai/Middleware/RequestLogger.hs+17−4
wai-extra/Network/Wai/Middleware/RequestLogger.hs+17−4
@@ -8,7 +8,7 @@ module Network.Wai.Middleware.RequestLogger
88 , logHandleDevLT
99 ) where
1010
11−import System.IO (stdout)
11+import System.IO (stdout, hFlush)
1212import qualified Data.ByteString as BS
1313import Data.ByteString.Char8 (pack)
1414import Control.Monad.IO.Class (liftIO)
@@ -30,13 +30,20 @@ logStdout :: Middleware
3030logStdout = logHandle $ \bs -> hPutLogStr stdout [LB bs]
3131
3232-- | like @logHandleDev@, but prints to 'stdout'
33+--
34+-- Note that this flushes 'stdout' on each call to make it useful for
35+-- development. This is very inefficient for production use.
3336logStdoutDev :: Middleware
34−logStdoutDev = logHandleDev $ \bs -> hPutLogStr stdout [LB bs]
37+logStdoutDev = logHandleDev $ \bs -> hPutLogStr stdout [LB bs] >> hFlush stdout
38+
39+-- FIXME This is not appropriately named at all. It's not working on a Handle,
40+-- it's working on a function. I find the functions in this module to be very
41+-- confusing.
42+-- - Michael
3543
3644-- | Prints a message using the given callback function for each request.
3745-- Designed for fast production use at the expense of convenience.
3846-- In particular, no POST parameter information is currently given
39−-- For something with more useful output, use Network.Wai.Middleware.Debug
4047logHandle :: (BS.ByteString -> IO ()) -> Middleware
4148logHandle cb app req = do
4249 liftIO $ cb $ BS.concat
@@ -54,6 +61,11 @@ logHandle cb app req = do
5461toBS :: H.Ascii -> BS.ByteString
5562toBS = id
5663
64+-- FIXME: What's the purpose of this function? Why would it ever be preferable
65+-- to logStdoutDev? And why is it implemented via unpack instead of using a
66+-- more efficient Data.Text.IO function?
67+-- - Michael
68+
5769-- | Inefficient, but convenient Development load logger middleware
5870-- Prints a message to 'stderr' for each request using logHandleDevLT
5971logStdoutDevLT :: Middleware
@@ -67,7 +79,8 @@ logHandleDevLT cb app req =
6779-- | Prints a message using the given callback function for each request.
6880-- This is not for serious production use- it is inefficient.
6981-- It immediately consumes a POST body and fills it back in and is otherwise inefficient
70−-- For production use use module Network.Wai.Middleware.RequestLogger
82+--
83+-- Note that this function will not flush output.
7184logHandleDev :: (BS.ByteString -> IO ()) -> Middleware
7285logHandleDev cb app req = do
7386 body <- requestBody req C.$$ CL.consume