拥有此代码:
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"
如何记录它:写入控制台或文件发送/接收的所有事件和数据?我没有找到关于登录文档的任何提及。
答案 0 :(得分:2)
sinkFile不进行任何记录。如果你想要一个除了sinkFile之外还做一些日志记录的管道,你必须自己编写它,尽管它应该相对简单。
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
或类似的东西。