summaryrefslogtreecommitdiffstats
path: root/src/Main.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-11-06 16:10:43 +0100
committertv <tv@shackspace.de>2014-11-06 16:10:43 +0100
commit9b2bea53c6bc87be639964aaca87c09ab16df486 (patch)
tree5bd768ccc901a357fbbf77ab337b2015eb486646 /src/Main.hs
parent781e26234dd1854c51895fa4fcc31f26f209c52f (diff)
Flush log after each request.
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ef7710f..66b4df6 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -56,6 +56,7 @@ import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.RequestLogger (logStdout)
import System.FilePath
import System.IO.Error
+import System.IO (hFlush, stdout)
-- | The sum of all resources known by the application.
@@ -79,10 +80,21 @@ main =
start :: Config -> IO ()
start c = do
putStrLn $ "run cgserver with " <> show c
+ hFlush stdout
run (httpPort c)
- $ logStdout
+ $ logger
$ \req ->
resourceHandler (requestResource c req) req
+ where
+ logger =
+ if flushLog c
+ then flush stdout . logStdout
+ else logStdout
+
+ -- This middleware flushes the given handle after each request.
+ flush h app req respond = app req $ \res -> do
+ hFlush h
+ respond res
-- | Determine which request is requested.