diff --git a/src/Env.hs b/src/Env.hs index f19784f..b928b33 100644 --- a/src/Env.hs +++ b/src/Env.hs @@ -2,7 +2,7 @@ module Env(Env(..), App(..), runMover, SourceFunctions(..)) where -import Log(Logger(..)) +import Log import Mover import Source import Destination @@ -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 ()) @@ -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) diff --git a/src/Log.hs b/src/Log.hs index 8e9df2e..1c1a9ec 100644 --- a/src/Log.hs +++ b/src/Log.hs @@ -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]