more linting and adding Log module

This commit is contained in:
nek0 2024-11-05 01:24:07 +01:00
parent bd5b74722c
commit 892333bb6e
3 changed files with 31 additions and 0 deletions

View file

@ -1,3 +1,4 @@
{-# LANGUAGE StrictData #-}
module Client.Types where
import qualified Control.Concurrent.STM as STM

View file

@ -1,4 +1,5 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
module Library.Types.Communication where
import Data.Aeson

29
src-server/Server/Log.hs Normal file
View file

@ -0,0 +1,29 @@
module Server.Log where
import Control.Monad (when)
import Control.Monad.RWS (asks, MonadIO (liftIO))
import Debug.Trace
-- internal imports
import Server.Types (LogLevel, Game, ReaderContainer (rcLogLevel))
logPrint
:: LogLevel
-> String
-> Game ()
logPrint level msg = do
curLevel <- asks rcLogLevel
when (level <= curLevel) $
liftIO $ traceIO $ show level <> ": " <> msg
logPrintIO
:: LogLevel
-> LogLevel
-> String
-> IO ()
logPrintIO curLevel level msg = do
when (level <= curLevel) $
liftIO $ traceIO $ show level <> ": " <> msg