summaryrefslogtreecommitdiff
path: root/cwality-maps
diff options
context:
space:
mode:
authorstuebinm2022-03-03 17:46:14 +0100
committerstuebinm2022-03-03 17:46:14 +0100
commit3d5618a92e660f4c15e278af8e53afb0486da866 (patch)
tree2b7ce1e2a2dfbaf364f8c19f31bbe95bf6c65b57 /cwality-maps
parenteedc2e5e03cb6e45d08eeecbf602536c55f79e8b (diff)
cwality-maps: better logging
Diffstat (limited to 'cwality-maps')
-rw-r--r--cwality-maps/Main.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/cwality-maps/Main.hs b/cwality-maps/Main.hs
index f242b94..39723f4 100644
--- a/cwality-maps/Main.hs
+++ b/cwality-maps/Main.hs
@@ -44,6 +44,9 @@ import Servant.Server.StaticFiles (serveDirectoryWebApp)
import Substitute (Substitutable (substitute),
SubstitutionError)
+import Control.Monad.Logger
+
+
-- | a map's filename ending in .json
-- (a newtype to differentiate between maps and assets in a route)
newtype JsonFilename = JsonFilename Text
@@ -87,14 +90,15 @@ mkMap :: Config True -> Tiledmap -> MapParams -> ([SubstitutionError], Tiledmap)
mkMap _config basemap params =
substitute basemap (substs params)
-
mapHandler :: Config True -> JsonFilename -> MapParams -> Handler Tiledmap
mapHandler config (JsonFilename mapname) params =
case M.lookup mapname (snd $ view template config) of
- Just basemap -> do
- let (errors, map) = mkMap config basemap params
- print errors
- pure map
+ Just basemap -> runStdoutLoggingT $
+ logWarnN (pretty errors) >> pure tiledmap
+ where (errors, tiledmap) = mkMap config basemap params
+ pretty errors = T.concat
+ . intersperse "\n "
+ $ concatMap (lines . show) errors
Nothing -> throwError err404
-- | Complete set of routes: API + HTML sites
@@ -106,6 +110,8 @@ server config = mapHandler config
app :: Config True -> Application
app = serve (Proxy @Routes) . server
+
+
main :: IO ()
main = do
config <- loadConfig "./cwality-config.toml"