@@ -10,11 +10,7 @@
1010
1111-- | Provides support for treating payloads and namespaces as
1212-- composable contexts. The common pattern would be to provide a
13−-- 'KatipContext' instance for your base monad. When your program
14−-- changes to a more detailed context, say to the database, you can
15−-- use 'LogT' to tack on a typed context and a namespace
16−-- which will be merged into the enclosing monad's context and
17−-- namespace.
13+-- 'KatipContext' instance for your base monad.
1814module Katip.Monadic
1915 (
2016 -- * Monadic variants of logging functions from "Katip.Core"
@@ -29,10 +25,10 @@ module Katip.Monadic
2925 , LogContexts
3026 , liftPayload
3127
32− -- * LogT - Utility transformer that provides Katip and KatipContext instances
33− , LogT(..)
34− , runLogT
35− , LogTState(..)
28+ -- * KatipContextT - Utility transformer that provides Katip and KatipContext instances
29+ , KatipContextT(..)
30+ , runKatipContextT
31+ , KatipContextTState(..)
3632 ) where
3733
3834
@@ -101,7 +97,7 @@ liftPayload = LogContexts . (:[]) . AnyLogContext
10197-------------------------------------------------------------------------------
10298-- | A monadic context that has an inherant way to get logging
10399-- context and namespace. Examples include a web application monad or
104−-- database monad. Combine with 'LogT' to nest.
100+-- database monad.
105101class Katip m => KatipContext m where
106102 getKatipContext :: m LogContexts
107103 getKatipNamespace :: m Namespace
@@ -202,12 +198,12 @@ logExceptionM action sev = action `catchAll` \e -> f e >> throwM e
202198-- le <- getLogEnv
203199-- ctx <- getKatipContext
204200-- ns <- getKatipNamespace
205−-- forkIO $ runLogT le ctx ns $ do
201+-- forkIO $ runKatipContextT le ctx ns $ do
206202-- $(logTM) InfoS "Look, I can log in IO and retain context!"
207203-- doOtherStuff
208204-- @
209−newtype LogT m a = LogT {
210− unLogT :: ReaderT LogTState m a
205+newtype KatipContextT m a = KatipContextT {
206+ unKatipContextT :: ReaderT KatipContextTState m a
211207 } deriving ( Functor
212208 , Applicative
213209 , Monad
@@ -226,30 +222,30 @@ newtype LogT m a = LogT {
226222 )
227223
228224
229−data LogTState = LogTState {
225+data KatipContextTState = KatipContextTState {
230226 ltsLogEnv :: !LogEnv
231227 , ltsContext :: !LogContexts
232228 , ltsNamespace :: !Namespace
233229 }
234230
235231-- Reader is a passthrough. We don't expose our internal reader so as not to conflict
236−instance (MonadReader r m) => MonadReader r (LogT m) where
232+instance (MonadReader r m) => MonadReader r (KatipContextT m) where
237233 ask = lift ask
238− local f (LogT (ReaderT m)) = LogT $ ReaderT $ \r ->
234+ local f (KatipContextT (ReaderT m)) = KatipContextT $ ReaderT $ \r ->
239235 local f (m r)
240236
241237
242−instance (MonadIO m) => Katip (LogT m) where
243− getLogEnv = LogT $ ReaderT $ \lts -> return (ltsLogEnv lts)
238+instance (MonadIO m) => Katip (KatipContextT m) where
239+ getLogEnv = KatipContextT $ ReaderT $ \lts -> return (ltsLogEnv lts)
244240
245241
246−instance (MonadIO m) => KatipContext (LogT m) where
247− getKatipContext = LogT $ ReaderT $ \lts -> return (ltsContext lts)
248− getKatipNamespace = LogT $ ReaderT $ \lts -> return (ltsNamespace lts)
242+instance (MonadIO m) => KatipContext (KatipContextT m) where
243+ getKatipContext = KatipContextT $ ReaderT $ \lts -> return (ltsContext lts)
244+ getKatipNamespace = KatipContextT $ ReaderT $ \lts -> return (ltsNamespace lts)
249245
250246
251247-------------------------------------------------------------------------------
252−runLogT :: (LogItem c) => LogEnv -> c -> Namespace -> LogT m a -> m a
253−runLogT le ctx ns = flip runReaderT lts . unLogT
248+runKatipContextT :: (LogItem c) => LogEnv -> c -> Namespace -> KatipContextT m a -> m a
249+runKatipContextT le ctx ns = flip runReaderT lts . unKatipContextT
254250 where
255− lts = LogTState le (liftPayload ctx) ns
251+ lts = KatipContextTState le (liftPayload ctx) ns