From 892333bb6ea199e081d1c11816fbce131d3f382c Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 5 Nov 2024 01:24:07 +0100 Subject: [PATCH] more linting and adding Log module --- src-client/Client/Types.hs | 1 + src-lib/Library/Types/Communication.hs | 1 + src-server/Server/Log.hs | 29 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src-server/Server/Log.hs diff --git a/src-client/Client/Types.hs b/src-client/Client/Types.hs index f24c5ca..dadbfb0 100644 --- a/src-client/Client/Types.hs +++ b/src-client/Client/Types.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE StrictData #-} module Client.Types where import qualified Control.Concurrent.STM as STM diff --git a/src-lib/Library/Types/Communication.hs b/src-lib/Library/Types/Communication.hs index 57f723c..52070ae 100644 --- a/src-lib/Library/Types/Communication.hs +++ b/src-lib/Library/Types/Communication.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE StrictData #-} module Library.Types.Communication where import Data.Aeson diff --git a/src-server/Server/Log.hs b/src-server/Server/Log.hs new file mode 100644 index 0000000..3d27258 --- /dev/null +++ b/src-server/Server/Log.hs @@ -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