simple-log 0.3.0 → 0.3.1
raw patch · 3 files changed
+20/−15 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- simple-log.cabal +3/−3
- src/System/Log/Simple/Base.hs +16/−11
- src/System/Log/Simple/Monad.hs +1/−1
simple-log.cabal view
@@ -1,5 +1,5 @@ Name: simple-log -Version: 0.3.0 +Version: 0.3.1 Synopsis: Simple log for Haskell Description: Log library for Haskell with removing unnecessary traces License: BSD3 @@ -23,8 +23,8 @@ MonadCatchIO-transformers >= 0.2 && < 0.4, mtl >= 2.0 && < 2.2, old-locale >= 1.0 && < 1.1, - SafeSemaphore == 0.9.*, - text == 0.11.*, + SafeSemaphore >= 0.9.0 && < 1.0.0, + text >= 0.11.0 && < 2.0.0, time >= 1.3 && < 1.5, transformers >= 0.2 && < 0.4 Exposed-Modules:
src/System/Log/Simple/Base.hs view
@@ -29,6 +29,8 @@ import Control.Concurrent.MSem import Control.DeepSeq import Control.Monad +import Control.Monad.IO.Class +import Control.Monad.CatchIO import Data.List import qualified Data.Map as M import Data.Text (Text) @@ -234,28 +236,31 @@ return $ Log writeCommand rs -- | Write message to log -writeLog :: Log -> Level -> Text -> IO () -writeLog (Log post _) l msg = do +writeLog :: MonadIO m => Log -> Level -> Text -> m () +writeLog (Log post _) l msg = liftIO $ do tm <- getZonedTime post $ PostMessage (Message tm l [] msg) -- | New log-scope -scopeLog_ :: Log -> Text -> IO a -> IO a +scopeLog_ :: MonadCatchIO m => Log -> Text -> m a -> m a scopeLog_ (Log post getRules) s act = do - rs <- getRules - sem <- new (0 :: Integer) - E.bracket_ (post $ EnterScope s rs) (post (LeaveScope $ signal sem) >> wait sem) act + rs <- liftIO getRules + sem <- liftIO $ new (0 :: Integer) + bracket_ + (liftIO $ post $ EnterScope s rs) + (liftIO $ post (LeaveScope $ signal sem) >> wait sem) + act -- | New log-scope with lifting exceptions as errors -scopeLog :: Log -> Text -> IO a -> IO a -scopeLog l s act = scopeLog_ l s (E.catch act onError) where - onError :: E.SomeException -> IO a +scopeLog :: MonadCatchIO m => Log -> Text -> m a -> m a +scopeLog l s act = scopeLog_ l s (catch act onError) where + onError :: MonadIO m => E.SomeException -> m a onError e = do writeLog l Error $ fromString $ "Scope leaves with exception: " ++ show e - E.throwIO e + throw e -- | New log-scope with tracing scope result -scoperLog :: Show a => Log -> Text -> IO a -> IO a +scoperLog :: MonadCatchIO m => Show a => Log -> Text -> m a -> m a scoperLog l s act = do r <- scopeLog l s act writeLog l Trace $ T.concat ["Scope ", s, " leaves with result: ", fromString . show $ r]
src/System/Log/Simple/Monad.hs view
@@ -97,7 +97,7 @@ scoperM :: (Error e, Show e, Show a, MonadLog m, MonadError e m) => Text -> m a -> m a scoperM s act = do r <- scopeM s act - log Trace $ T.concat ["Scope", s, " leaves with resul: ", fromString . show $ r] + log Trace $ T.concat ["Scope", s, " leaves with result: ", fromString . show $ r] return r -- | Ignore error