wizard-wipeout/src-client/Client/Log.hs
2024-12-17 10:03:05 +01:00

31 lines
752 B
Haskell

module Client.Log where
import Control.Monad (when)
import Control.Monad.RWS (asks, MonadIO (liftIO))
import Debug.Trace (traceIO)
-- internal imports
import Client.Types (Game, LogLevel, ReaderContainer(rcLogLevel))
-- | Print a log line
logPrint
:: LogLevel -- ^ Desired log level of message
-> String -- ^ The message
-> Game ()
logPrint level msg = do
curLevel <- asks rcLogLevel
when (level <= curLevel) $
liftIO $ traceIO $ show level <> ": " <> msg
-- | Print a log line
logPrintIO
:: LogLevel -- ^ Current log level
-> LogLevel -- ^ Desired log level of message
-> String -- ^ The message
-> IO ()
logPrintIO curLevel level msg = do
when (level <= curLevel) $
liftIO $ traceIO $ show level <> ": " <> msg