1

So I'm having something odd happen. Here's an illustrative code example:

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

My message should print to the IntelliJ console whenever I type in "localhost:8000/", but it doesn't. Yet when I comment out the scotty stuff and just have:

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

IntelliJ has no problem printing this out. What am I doing wrong? When I use the Windows command prompt to run the executable (e.g. ghc --make to create it, then running it), everything works fine - "I'm about to serve a request!" prints to the command prompt terminal everytime I Type in "localhost:8000/"

Enis
  • 171
  • 9
  • Is something in the scotty stack redirecting stdout? Maybe capturing it for logging and emitting it on stderr? I'm not familiar with intellij – jberryman Jun 03 '17 at 17:00
  • You were right, it was. Just answered my own question. So annoying... – Enis Jun 03 '17 at 17:29

1 Answers1

0

Figured it out. Needed to make a logger as follows:

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

so that the resulting code would look like:

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

The CustomOutputFormat ignores all other incoming information, focusing only on what you want to print to the console.

Enis
  • 171
  • 9