on master help sign in
logStdoutDev flushes
98e8a3dMichael Snoyman
wai-extra/Network/Wai/Middleware/RequestLogger.hs+17−4
@@ -8,7 +8,7 @@ module Network.Wai.Middleware.RequestLogger
8 , logHandleDevLT
8 , logHandleDevLT
9 ) where
9 ) where
10
10
11−import System.IO (stdout)
11+import System.IO (stdout, hFlush)
12import qualified Data.ByteString as BS
12import qualified Data.ByteString as BS
13import Data.ByteString.Char8 (pack)
13import Data.ByteString.Char8 (pack)
14import Control.Monad.IO.Class (liftIO)
14import Control.Monad.IO.Class (liftIO)
@@ -30,13 +30,20 @@ logStdout :: Middleware
30logStdout = logHandle $ \bs -> hPutLogStr stdout [LB bs]
30logStdout = logHandle $ \bs -> hPutLogStr stdout [LB bs]
31
31
32-- | like @logHandleDev@, but prints to 'stdout'
32-- | 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.
33logStdoutDev :: Middleware
36logStdoutDev :: 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
35
43
36-- | Prints a message using the given callback function for each request.
44-- | Prints a message using the given callback function for each request.
37-- Designed for fast production use at the expense of convenience.
45-- Designed for fast production use at the expense of convenience.
38-- In particular, no POST parameter information is currently given
46-- In particular, no POST parameter information is currently given
39−-- For something with more useful output, use Network.Wai.Middleware.Debug
40logHandle :: (BS.ByteString -> IO ()) -> Middleware
47logHandle :: (BS.ByteString -> IO ()) -> Middleware
41logHandle cb app req = do
48logHandle cb app req = do
42 liftIO $ cb $ BS.concat
49 liftIO $ cb $ BS.concat
@@ -54,6 +61,11 @@ logHandle cb app req = do
54toBS :: H.Ascii -> BS.ByteString
61toBS :: H.Ascii -> BS.ByteString
55toBS = id
62toBS = id
56
63
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+
57-- | Inefficient, but convenient Development load logger middleware
69-- | Inefficient, but convenient Development load logger middleware
58-- Prints a message to 'stderr' for each request using logHandleDevLT
70-- Prints a message to 'stderr' for each request using logHandleDevLT
59logStdoutDevLT :: Middleware
71logStdoutDevLT :: Middleware
@@ -67,7 +79,8 @@ logHandleDevLT cb app req =
67-- | Prints a message using the given callback function for each request.
79-- | Prints a message using the given callback function for each request.
68-- This is not for serious production use- it is inefficient.
80-- This is not for serious production use- it is inefficient.
69-- It immediately consumes a POST body and fills it back in and is otherwise inefficient
81-- 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.
71logHandleDev :: (BS.ByteString -> IO ()) -> Middleware
84logHandleDev :: (BS.ByteString -> IO ()) -> Middleware
72logHandleDev cb app req = do
85logHandleDev cb app req = do
73 body <- requestBody req C.$$ CL.consume
86 body <- requestBody req C.$$ CL.consume