@@ -32,6 +32,8 @@ module Katip.Monadic
32 , ContextualLogT'
32 , ContextualLogT'
33 , ContextualLogT
33 , ContextualLogT
34 , runContextualLogT
34 , runContextualLogT
36+ , runBlankLogContextT
@@ -202,6 +204,7 @@ newtype ContextualLogT' n m a = ContextualLogT {
202 , MonadIO
204 , MonadIO
203 , MonadThrow
205 , MonadThrow
204 , MonadCatch
206 , MonadCatch
205 , MonadBase b
208 , MonadBase b
206 , MonadState s
209 , MonadState s
207 , MonadWriter w
210 , MonadWriter w
@@ -244,7 +247,6 @@ instance (ContextualLog m, Monad m) => ContextualLog (ContextualLogT' m m) where
244 nsInner <- getNsInner
247 nsInner <- getNsInner
245 return $ nsOuter <> nsInner
248 return $ nsOuter <> nsInner
248runContextualLogT
250runContextualLogT
249 :: (Functor m, LogContext a)
251 :: (Functor m, LogContext a)
@@ -253,3 +255,44 @@ runContextualLogT
254runContextualLogT lgtr nsgtr m = runReaderT (unContextualLogT m) (liftPayload <$> lgtr, nsgtr)
256runContextualLogT lgtr nsgtr m = runReaderT (unContextualLogT m) (liftPayload <$> lgtr, nsgtr)
259+-------------------------------------------------------------------------------
260+-- | Type analogous to IdentityT that provides an empty log
261+-- context. Use this if your root monad doesn't have a LogContext instance.
262+newtype BlankLogContextT m a = BlankLogContextT {
263+ runBlankLogContextT :: m a
264+ } deriving ( Functor
281+instance Monad m => ContextualLog (BlankLogContextT m) where
282+ getLogContexts = return mempty
283+ getNamespace = return mempty
285+instance MonadTrans BlankLogContextT where
286+ lift = BlankLogContextT
288+instance MonadTransControl BlankLogContextT where
289+ type StT BlankLogContextT a = a
290+ liftWith f = BlankLogContextT $ f runBlankLogContextT
291+ restoreT = BlankLogContextT
292+ {-# INLINABLE liftWith #-}
293+ {-# INLINABLE restoreT #-}
295+instance (MonadBaseControl b m) => MonadBaseControl b (BlankLogContextT m) where
296+ type StM (BlankLogContextT m) a = ComposeSt BlankLogContextT m a
297+ liftBaseWith = defaultLiftBaseWith
298+ restoreM = defaultRestoreM