Skip to content

Commit

Permalink
add default error and debug log functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHajdu committed Nov 22, 2019
1 parent 0e79e0a commit 3d19ae3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Env(Env(..), App(..), runMover, SourceFunctions(..)) where

import Log(Logger(..))
import Log
import Mover
import Source
import Destination
Expand All @@ -11,7 +11,6 @@ import Message
import Filter
import Control.Monad.Trans.Reader (ReaderT)
import Control.Monad.Reader (MonadReader, liftIO, ask, asks, MonadIO, runReaderT)
import qualified Data.Text.IO as T(putStrLn)

data SourceFunctions = MkSourceFunctions (IO (Either NoMessageReason Message)) ([ReceiveId] -> IO ())

Expand Down Expand Up @@ -42,8 +41,8 @@ instance Filter App where
liftIO $ (envFilterAction env) msg

instance Logger App where
logError = liftIO . T.putStrLn
logDebug = logError
logError = ioErrorLog
logDebug = ioDebugLog

runMover :: Env -> IO ()
runMover = runReaderT (run moveMessages)
13 changes: 12 additions & 1 deletion src/Log.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
module Log(Logger(..)) where
module Log(Logger(..), ioErrorLog, ioDebugLog) where

import Data.Text
import qualified Data.Text.IO as TIO(putStrLn)
import qualified Data.Text as T(concat)
import Control.Monad.IO.Class(MonadIO, liftIO)

class Monad m => Logger m where
logError :: Text -> m ()
logDebug :: Text -> m ()

ioErrorLog :: MonadIO m => Text -> m ()
ioErrorLog = ioLog "ERROR "

ioDebugLog :: MonadIO m => Text -> m ()
ioDebugLog = ioLog "DEBUG "

ioLog :: MonadIO m => Text -> Text -> m ()
ioLog prefix msg = liftIO $ TIO.putStrLn $ T.concat [prefix, msg]

0 comments on commit 3d19ae3

Please sign in to comment.