2017-06-03 63 views
1

所以我有一些奇怪的事情发生。下面是一个说明性的代码示例:如何用Intellij(Haskell插件)使用scotty登录到终端?

main :: IO() 
main 
= do 
    scotty 8000 $ do 
     get "/" serve 
where 
    serve :: ActionM() 
    serve = do 
    liftIO $ print "I'm about to serve a request!" 

我的消息应该打印到控制台的IntelliJ每当我输入“本地主机:8000 /”,但事实并非如此。然而,当我注释掉scotty的东西,只是有:

main :: IO() 
main 
= do print "Hello World!" 

IntelliJ没有问题打印出来。我究竟做错了什么?当我使用Windows命令提示符运行可执行文件(例如ghc --make来创建它,然后运行它)时,一切正常 - “我即将提供请求!”打印到命令提示符终端,每次输入“localhost:8000 /”

+0

是scotty堆栈重定向标准输出的东西?也许捕获它的记录和放在stderr?我不熟悉intellij – jberryman

+0

你是对的,是的。刚回答我自己的问题。很烦人... – Enis

回答

0

找出来。需要做出记录如下:

logger <- mkRequestLogger def { 
    outputFormat = CustomOutputFormat (\_ _ _ _ -> "") 
    } 

使得所得到的代码是这样:

main :: IO() 
main 
= do 
    logger <- mkRequestLogger def { 
     outputFormat = CustomOutputFormat (\_ _ _ _ -> "") 
     } 
    scotty 8000 $ do 
     middleware logger 
     -- do stuff here 

的CustomOutputFormat忽略所有其他传入信息,只注重要打印到控制台什么。