@@ -34,6 +34,7 @@ module Katip.Monadic
34 , katipAddNamespace
34 , katipAddNamespace
35 , katipAddContext
35 , katipAddContext
36 , KatipContextTState(..)
36 , KatipContextTState(..)
@@ -43,6 +44,7 @@ import Control.Exception.Safe
43import Control.Monad.Base
44import Control.Monad.Base
44import Control.Monad.Error.Class
45import Control.Monad.Error.Class
45import Control.Monad.IO.Class
46import Control.Monad.IO.Class
47+import Control.Monad.IO.Unlift
46import Control.Monad.Reader
48import Control.Monad.Reader
47import Control.Monad.State
49import Control.Monad.State
48import Control.Monad.Trans.Control
50import Control.Monad.Trans.Control
@@ -389,6 +391,11 @@ instance (MonadIO m) => KatipContext (KatipContextT m) where
389 getKatipNamespace = KatipContextT $ ReaderT $ \lts -> return (ltsNamespace lts)
391 getKatipNamespace = KatipContextT $ ReaderT $ \lts -> return (ltsNamespace lts)
390 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
392 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
394+instance MonadUnliftIO m => MonadUnliftIO (KatipContextT m) where
395+ askUnliftIO = KatipContextT $
396+ withUnliftIO $ \u ->
397+ pure (UnliftIO (unliftIO u . unKatipContextT))
393-------------------------------------------------------------------------------
400-------------------------------------------------------------------------------
394runKatipContextT :: (LogItem c) => LogEnv -> c -> Namespace -> KatipContextT m a -> m a
401runKatipContextT :: (LogItem c) => LogEnv -> c -> Namespace -> KatipContextT m a -> m a
@@ -429,3 +436,53 @@ katipAddContext
431katipAddContext i = localKatipContext (<> (liftPayload i))
438katipAddContext i = localKatipContext (<> (liftPayload i))
440+newtype NoLoggingT m a = NoLoggingT {
441+ runNoLoggingT :: m a
442+ } deriving ( Functor
458+instance MonadTrans NoLoggingT where
461+instance MonadTransControl NoLoggingT where
462+ type StT NoLoggingT a = a
463+ liftWith f = NoLoggingT $ f runNoLoggingT
464+ restoreT = NoLoggingT
465+ {-# INLINE liftWith #-}
466+ {-# INLINE restoreT #-}
468+instance MonadBaseControl b m => MonadBaseControl b (NoLoggingT m) where
469+ type StM (NoLoggingT m) a = StM m a
470+ liftBaseWith f = NoLoggingT $
471+ liftBaseWith $ \runInBase ->
472+ f $ runInBase . runNoLoggingT
473+ restoreM = NoLoggingT . restoreM
475+instance MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) where
476+ askUnliftIO = NoLoggingT $
477+ withUnliftIO $ \u ->
478+ pure (UnliftIO (unliftIO u . runNoLoggingT))
480+instance MonadIO m => Katip (NoLoggingT m) where
481+ getLogEnv = liftIO (initLogEnv "NoLoggingT" "no-logging")
482+ localLogEnv = const id
484+instance MonadIO m => KatipContext (NoLoggingT m) where
485+ getKatipContext = pure mempty
486+ localKatipContext = const id
487+ getKatipNamespace = pure mempty
488+ localKatipNamespace = const id