logging in web applications

agentultra 2018-03-08 18:49:43.327407 UTC

1import qualified Control.Concurrent as Concurrent
2import qualified Control.Monad.Logger (NoLoggingT (..), runNoLoggingT) as Log
3import qualified Database.Persist.Sqlite as DB
4import qualified Eventful.Store.Sqlite as ES
5import qualified Network.Wai as Wai
6import qualified Network.Wai.Handler.Warp as Warp
7import qualified Network.Wai.Handler.WebSockets as WS
8import qualified Network.WebSockets as WS
9
10-- I want to setup logging but if I turn `runNoLoggingT` into something else
11-- the type errors are too difficult for me to understand as I don't fully grasp
12-- mtl/transformers yet... and the documentation for this library is also impenetrable
13-- without such a background. Are there any good resources/tutorials/examples/gentle-
14-- introductions I could throw myself at? The simplest possible thing right now is just
15-- to get this to log to stdout for now and maybe pick up mtl-style along the way.
16main :: IO ()
17main = Log.runNoLoggingT $ DB.withSqlitePool "test.db" 1 $ \pool -> Log.NoLoggingT $ do
18 ES.initializeSqliteEventStore ES.defaultSqlEventStoreConfig pool
19 state <- Concurrent.newMVar []
20 Warp.run 3000 $ WS.websocketsOr
21 WS.defaultConnectionOptions
22 (wsApp pool state)
23 httpApp