How to disable logging per request in yesod?


I’ve noticed that after deploying a small yesod that each request is being logged to output. I’ve tried searching for a setting to disable this but I cannot find anything. Does anyone know how to disable this?

Edit: I did not use the scaffold to create the app.


I don’t exactly know where the per-request loging is, but the loging settings or at least part of them are set in Foundation.hs (assuming you use the scaffolding code). Maybe this helps.


Sorry I should have specified. I did not use the scaffold (I had some issues with that).


Then how did you set up logging?


I think there is probably some logging happening by default. Yesod is typically used together with warp which serves as the actual HTTP server running your Yesod application.

By using warp’s runSettings rather than run you should be able to pass in additional settings, including logging settings. This should probably go in tour main function somewhere. Hope this helps!


@wiz I’ve been useing the guide from the yesod book here. If you go to the section I/O and debugging, you can see that the shouldLogIO is overridden to return True. I’ve overridden that to return False this turned of the initial log output when you start the application but each request is still being logged to the console.

@jaspervdj thanks for the suggestion. I checked out the defaultSettings funciton that should be ran when you use the run command vs the runSettings command.

defaultSettings :: Settings
defaultSettings = Settings
    { settingsPort = 3000
    , settingsLogger = \_ _ _ -> return ()

It appears that it’s set to not output anything.

As is in the book example provided above, I am running with something like

main :: IO ()
main = warp 3000 App

the warp function is from the Yesod.Core and I’m looking around in there to see if there’s anything else that disables logging besides shouldLogIO.


Huh. I’ve checked out shouldLogIO method and it indeed does not have access to a http request. It appears that it is for site-specific log messages that could be toggled while the site is running.

Default logging middleware may have no hooks to filter requests. I think you can use replace default middleware set with your own, where its logging middleware is wrapped in your filter function. Middleware is just a function that gets request and you can make a choice to invoke request logging or skip it.