on master help sign in
Merge remote-tracking branch 'origin/master'

Conflicts: wai-extra/wai-extra.cabal

commit92cd3273d651968b055aff19503b9697ee25e2ca authorMichael Snoyman <michael@snoyman.com> dateTue 24 Jan 2012, 12:13 (15 years ago) parent79851df5b7232b
6 files changed+32−41
wai-extra/Network/Wai/Middleware/RequestLogger.hs+27−36 wai-extra/wai-extra.cabal+1−1 wai-handler-devel/wai-handler-devel.cabal+1−1 wai-handler-fastcgi/wai-handler-fastcgi.cabal+1−1 wai-handler-scgi/wai-handler-scgi.cabal+1−1 warp-static/warp-static.cabal+1−1
wai-extra/Network/Wai/Middleware/RequestLogger.hs+27−36
@@ -1,11 +1,12 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Network.Wai.Middleware.RequestLogger
33 ( logStdout
4− , logHandle
4+ , logCallback
55 , logStdoutDev
6+ , logCallbackDev
7+ -- * Deprecated
8+ , logHandle
69 , logHandleDev
7− , logStdoutDevLT
8− , logHandleDevLT
910 ) where
1011
1112import System.IO (stdout, hFlush)
@@ -15,37 +16,41 @@ import Control.Monad.IO.Class (liftIO)
1516import Network.Wai (Request(..), Middleware)
1617import System.Log.FastLogger
1718import Network.HTTP.Types as H
18−import qualified Data.Text.Lazy as LT
19−import qualified Data.Text.Encoding as TE
2019
2120import Network.Wai.Parse (parseRequestBody, lbsSink, fileName, Param, File)
2221import qualified Data.ByteString.Lazy as LBS
23−import System.IO (hPutStrLn, stderr)
2422
2523import qualified Data.Conduit as C
2624import qualified Data.Conduit.List as CL
2725
28−-- | like @logHandle@, but prints to 'stdout'
26+logHandle :: (BS.ByteString -> IO ()) -> Middleware
27+logHandle = logCallback
28+{-# DEPRECATED logHandle "Please use logCallback instead." #-}
29+logHandleDev :: (BS.ByteString -> IO ()) -> Middleware
30+logHandleDev = logCallbackDev
31+{-# DEPRECATED logHandleDev "Please use logCallbackDev instead." #-}
32+
33+-- | Production request logger middleware.
34+-- Implemented on top of "logCallback", but prints to 'stdout'
2935logStdout :: Middleware
3036logStdout = logHandle $ \bs -> hPutLogStr stdout [LB bs]
3137
32−-- | like @logHandleDev@, but prints to 'stdout'
38+-- | Development request logger middleware.
39+-- Implemented on top of "logCallbackDev", but prints to 'stdout'
3340--
34−-- Note that this flushes 'stdout' on each call to make it useful for
35−-- development. This is very inefficient for production use.
41+-- Flushes 'stdout' on each request, which would be inefficient in production use.
42+-- Use "logStdout" in production.
3643logStdoutDev :: Middleware
3744logStdoutDev = logHandleDev $ \bs -> hPutLogStr stdout [LB bs] >> hFlush stdout
3845
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
43−
4446-- | Prints a message using the given callback function for each request.
4547-- Designed for fast production use at the expense of convenience.
4648-- In particular, no POST parameter information is currently given
47−logHandle :: (BS.ByteString -> IO ()) -> Middleware
48−logHandle cb app req = do
49+--
50+-- This is lower-level - use "logStdout" unless you need this greater control
51+logCallback :: (BS.ByteString -> IO ()) -- ^ A function that logs the ByteString log message.
52+ -> Middleware
53+logCallback cb app req = do
4954 liftIO $ cb $ BS.concat
5055 [ requestMethod req
5156 , " "
@@ -61,28 +66,14 @@ logHandle cb app req = do
6166toBS :: H.Ascii -> BS.ByteString
6267toBS = id
6368
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−
69−-- | Inefficient, but convenient Development load logger middleware
70−-- Prints a message to 'stderr' for each request using logHandleDevLT
71−logStdoutDevLT :: Middleware
72−logStdoutDevLT = logHandleDevLT $ hPutStrLn stderr . LT.unpack
73−
74−-- | logHandleDev, but expects Lazy Text instead of a ByteString
75−logHandleDevLT :: (LT.Text -> IO ()) -> Middleware
76−logHandleDevLT cb app req =
77− logHandleDev (\msg -> cb $ LT.fromStrict $ TE.decodeUtf8 msg) app req
78−
7969-- | Prints a message using the given callback function for each request.
8070-- This is not for serious production use- it is inefficient.
8171-- It immediately consumes a POST body and fills it back in and is otherwise inefficient
8272--
83−-- Note that this function will not flush output.
84−logHandleDev :: (BS.ByteString -> IO ()) -> Middleware
85−logHandleDev cb app req = do
73+-- This is lower-level - use "logStdoutDev" unless you need this greater control
74+logCallbackDev :: (BS.ByteString -> IO ()) -- ^ A function that logs the ByteString log message.
75+ -> Middleware
76+logCallbackDev cb app req = do
8677 body <- requestBody req C.$$ CL.consume
8778 postParams <- if any (requestMethod req ==) ["GET", "HEAD"]
8879 then return []
@@ -101,7 +92,7 @@ logHandleDev cb app req = do
10192 , paramsToBS "POST " postParams
10293 , "\n"
10394 ]
104− -- we just consumed the body- fill the enumerator back up so it is available again
95+ -- The body was consumed. Fill it back up so it is available again
10596 app req { requestBody = CL.sourceList body }
10697 where
10798 paramsToBS prefix params =
wai-extra/wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
11Name: wai-extra
2−Version: 1.0.0.1
2+Version: 1.1.0
33Synopsis: Provides some basic WAI handlers and middleware.
44Description: The goal here is to provide common features without many dependencies.
55License: BSD3
wai-handler-devel/wai-handler-devel.cabal+1−1
@@ -23,7 +23,7 @@ Source-repository head
2323Library
2424 Build-Depends: base >= 4 && < 5
2525 , wai >= 1.0 && < 1.1
26− , wai-extra >= 1.0 && < 1.1
26+ , wai-extra >= 1.0 && < 1.2
2727 , http-types >= 0.6 && < 0.7
2828 , warp >= 1.0 && < 1.1
2929 , directory >= 1.0.1 && < 1.2
wai-handler-fastcgi/wai-handler-fastcgi.cabal+1−1
@@ -16,7 +16,7 @@ description: Calls out to the libfcgi C library.
1616library
1717 build-depends: base >= 4 && < 5
1818 , wai >= 1.0 && < 1.1
19− , wai-extra >= 1.0 && < 1.1
19+ , wai-extra >= 1.0 && < 1.2
2020 , bytestring >= 0.9.1.4 && < 0.10
2121 exposed-modules: Network.Wai.Handler.FastCGI
2222 ghc-options: -Wall
wai-handler-scgi/wai-handler-scgi.cabal+1−1
@@ -15,7 +15,7 @@ description: Wai handler to SCGI
1515library
1616 build-depends: base >= 4 && < 5
1717 , wai >= 1.0 && < 1.1
18− , wai-extra >= 1.0 && < 1.1
18+ , wai-extra >= 1.0 && < 1.2
1919 , bytestring >= 0.9.1.4 && < 0.10
2020 exposed-modules: Network.Wai.Handler.SCGI
2121 ghc-options: -Wall
warp-static/warp-static.cabal+1−1
@@ -17,7 +17,7 @@ Executable warp
1717 Build-depends: base >= 4 && < 5
1818 , warp >= 1.0 && < 1.1
1919 , wai-app-static >= 1.0 && < 1.1
20− , wai-extra >= 1.0 && < 1.1
20+ , wai-extra >= 1.0 && < 1.2
2121 , cmdargs >= 0.6.7
2222 , directory >= 1.0
2323 , containers >= 0.2 && < 0.5