monad-logger 0.3.16 → 0.3.17
raw patch · 3 files changed
+32/−2 lines, 3 files
Files
- ChangeLog.md +4/−0
- Control/Monad/Logger.hs +27/−1
- monad-logger.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.3.17++* log to a chan [#74](https://github.com/kazu-yamamoto/logger/pull/74)+ ## 0.3.16 * Provide default monadLoggerLog implementation [#72](https://github.com/kazu-yamamoto/logger/pull/72)
Control/Monad/Logger.hs view
@@ -36,6 +36,8 @@ , LoggingT (..) , runStderrLoggingT , runStdoutLoggingT+ , runChanLoggingT+ , unChanLoggingT , withChannelLogger , filterLogger , NoLoggingT (..)@@ -80,10 +82,11 @@ import Data.Monoid (Monoid) import Control.Applicative (Applicative (..))+import Control.Concurrent.Chan (Chan(),writeChan,readChan) import Control.Concurrent.STM import Control.Concurrent.STM.TBChan import Control.Exception.Lifted (onException)-import Control.Monad (liftM, ap, when, void)+import Control.Monad (liftM, ap, when, void, forever) import Control.Monad.Base (MonadBase (liftBase)) import Control.Monad.Loops (untilM) import Control.Monad.Trans.Control (MonadBaseControl (..), MonadTransControl (..))@@ -578,6 +581,29 @@ -- Since 0.2.2 runStdoutLoggingT :: MonadIO m => LoggingT m a -> m a runStdoutLoggingT = (`runLoggingT` defaultOutput stdout)++-- | Run a block using a @MonadLogger@ instance which writes tuples to an+-- unbounded channel.+--+-- The tuples can be extracted (ie. in another thread) with `unChanLoggingT`+-- or a custom extraction funtion, and written to a destination.+--+-- @since 0.3.17+runChanLoggingT :: MonadIO m => Chan (Loc, LogSource, LogLevel, LogStr) -> LoggingT m a -> m a+runChanLoggingT chan = (`runLoggingT` sink chan)+ where+ sink chan loc src lvl msg = writeChan chan (loc,src,lvl,msg)++-- | Read logging tuples from an unbounded channel and log them into a+-- `MonadLoggerIO` monad, forever.+--+-- For use in a dedicated thread with a channel fed by `runChanLoggingT`.+--+-- @since 0.3.17+unChanLoggingT :: (MonadLogger m, MonadIO m) => Chan (Loc, LogSource, LogLevel, LogStr) -> m ()+unChanLoggingT chan = forever $ do+ (loc,src,lvl,msg) <- liftIO $ readChan chan+ monadLoggerLog loc src lvl msg -- | Within the 'LoggingT' monad, capture all log messages to a bounded -- channel of the indicated size, and only actually log them if there is an
monad-logger.cabal view
@@ -1,5 +1,5 @@ name: monad-logger-version: 0.3.16+version: 0.3.17 synopsis: A class of monads which can log messages. description: Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/monad-logger>. homepage: https://github.com/kazu-yamamoto/logger