Skip to content

Commit

Permalink
add logging to the webserver (#106)
Browse files Browse the repository at this point in the history
This was surprisingly easy! I like the colors and whitespace of the development log format, though if I want "proper" server logs I should go with the production option, `logStdout` instead.


* add logging to the webserver

* alphabetize dependencies
  • Loading branch information
penguinland authored Oct 14, 2024
1 parent 649b55c commit f40860a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ executables:
- mtl
- Spock
- text
- wai-extra
- wai-middleware-static
5 changes: 4 additions & 1 deletion server/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Control.Monad.Trans(liftIO)
import Control.Monad.Trans.State.Strict(runStateT)
import Data.IORef(IORef, newIORef, readIORef, writeIORef)
import Data.Text(pack)
-- Take the `Dev` off the end to get more standardized server logs.
import Network.Wai.Middleware.RequestLogger(logStdoutDev)
import Network.Wai.Middleware.Static(staticPolicy, addBase)
import System.Random(StdGen, getStdGen)
import Web.Spock(SpockM, file, text, get, root, spock, runSpock, json,
Expand All @@ -31,7 +33,8 @@ main = do

app :: SpockM () MySession MyAppState ()
app = do
-- NOTE: these first two are relative to the current working directory when
middleware logStdoutDev
-- NOTE: these next two are relative to the current working directory when
-- you execute the program! So, you need to run it from the right place.
middleware (staticPolicy (addBase "static"))
get root $ file "text/html" "static/index.html"
Expand Down

0 comments on commit f40860a

Please sign in to comment.