logging 1.0.0 → 1.1.0
raw patch · 2 files changed
+63/−6 lines, 2 files
Files
- Control/Logging.hs +62/−5
- logging.cabal +1/−1
Control/Logging.hs view
@@ -1,16 +1,35 @@ {-# OPTIONS_GHC -Wall -fno-warn-orphans #-} +-- | Quick example of how to use this module:+--+-- @import Control.Logging+--+-- main = withStdoutLogging $ do+-- log "This is a log message!"+-- timedLog "This is a timed log message!" $ threadDelay 100000+-- @+ module Control.Logging ( log+ , log' , warn+ , warn' , debug+ , debug' , errorL+ , errorL' , traceL+ , traceL' , traceShowL+ , traceShowL' , timedLog , timedLog'+ , timedLogEnd+ , timedLogEnd' , timedDebug , timedDebug'+ , timedDebugEnd+ , timedDebugEnd' , withStdoutLogging , withStderrLogging , flushLog@@ -115,25 +134,47 @@ log :: MonadLogger m => Text -> m () log = logInfoN +-- | The apostrophe varients of the logging functions flush the log after each+-- message.+log' :: (MonadLogger m, MonadIO m) => Text -> m ()+log' msg = log msg >> flushLog+ debug :: MonadLogger m => Text -> m () debug = logDebugN +debug' :: (MonadLogger m, MonadIO m) => Text -> m ()+debug' msg = debug msg >> flushLog+ warn :: MonadLogger m => Text -> m () warn = logWarnN +warn' :: (MonadLogger m, MonadIO m) => Text -> m ()+warn' msg = warn msg >> flushLog+ -- | A logging variant of 'error' which uses 'unsafePerformIO' to output a log -- message before calling 'error'. errorL :: Text -> a errorL str = error (unsafePerformIO (logErrorN str) `seq` unpack str) +errorL' :: Text -> a+errorL' str = error (unsafePerformIO (logErrorN str >> flushLog) `seq` unpack str)+ traceL :: Text -> a -> a traceL str = trace (unsafePerformIO (logDebugN str) `seq` unpack str) +traceL' :: Text -> a -> a+traceL' str = trace (unsafePerformIO (logDebugN str >> flushLog) `seq` unpack str)+ traceShowL :: Show a => a -> a1 -> a1 traceShowL x = let s = show x in trace (unsafePerformIO (logDebugN (pack s)) `seq` s) +traceShowL' :: Show a => a -> a1 -> a1+traceShowL' x =+ let s = show x+ in trace (unsafePerformIO (logDebugN (pack s) >> flushLog) `seq` s)+ doTimedLog :: (MonadLogger m, MonadBaseControl IO m, MonadIO m) => (Text -> m ()) -> Bool -> Text -> m () -> m () doTimedLog logf wrapped msg f = do@@ -159,17 +200,33 @@ => Text -> m () -> m () timedLog = doTimedLog log True --- | Like 'timedLog', except that it does only logs when the action has--- completed or faileda. timedLog' :: (MonadLogger m, MonadBaseControl IO m, MonadIO m) => Text -> m () -> m ()-timedLog' = doTimedLog log False+timedLog' msg f = doTimedLog log True msg f >> flushLog +-- | Like 'timedLog', except that it does only logs when the action has+-- completed or failed after it is done.+timedLogEnd :: (MonadLogger m, MonadBaseControl IO m, MonadIO m)+ => Text -> m () -> m ()+timedLogEnd = doTimedLog log False++timedLogEnd' :: (MonadLogger m, MonadBaseControl IO m, MonadIO m)+ => Text -> m () -> m ()+timedLogEnd' msg f = doTimedLog log False msg f >> flushLog+ -- | A debug variant of 'timedLog'. timedDebug :: (MonadLogger m, MonadBaseControl IO m, MonadIO m) => Text -> m () -> m () timedDebug = doTimedLog debug True timedDebug' :: (MonadLogger m, MonadBaseControl IO m, MonadIO m)- => Text -> m () -> m ()-timedDebug' = doTimedLog debug False+ => Text -> m () -> m ()+timedDebug' msg f = doTimedLog debug True msg f >> flushLog++timedDebugEnd :: (MonadLogger m, MonadBaseControl IO m, MonadIO m)+ => Text -> m () -> m ()+timedDebugEnd = doTimedLog debug False++timedDebugEnd' :: (MonadLogger m, MonadBaseControl IO m, MonadIO m)+ => Text -> m () -> m ()+timedDebugEnd' msg f = doTimedLog debug False msg f >> flushLog
logging.cabal view
@@ -1,5 +1,5 @@ Name: logging-Version: 1.0.0+Version: 1.1.0 Synopsis: Simplified logging in IO for application writers. License-file: LICENSE License: MIT