Reputation: 34884
Having this code:
import Data.Conduit.Binary (sinkFile)
import Network.HTTP.Conduit
import qualified Data.Conduit as C
main :: IO ()
main = do
request <- parseUrl "http://google.com/"
withManager $ \manager -> do
response <- http request manager
responseBody response C.$$+- sinkFile "google.html"
How do I log it: write to the console or a file all the events and data sent/received? I didn't find any mention about logging in the documentation.
Upvotes: 0
Views: 64
Reputation: 3202
sinkFile doesn't do any logging. If you want a conduit that does some logging in addition to what sinkFile does, you'll have to write it yourself, although it should be relatively simple.
logSinkFile filename = logSinkIOHandle (IO.openBinaryFile fp IO.WriteMode)
logSinkIOHandle alloc = bracketP alloc IO.hClose logSinkHandle
logSinkHandle h = go
where go = do
liftIO $ putStrLn "Awaiting data."
mbs <- await
case mbs of
Nothing -> return ()
Maybe bs -> do
liftIO $ do
putStrLn "Data Ready."
putStr "Writing data: "
S.put bs
putStrLn ""
S.hPut h bs
putStrLn "Data written."
go
Or something like that.
Upvotes: 2