@@ -10,11 +10,7 @@
11-- | Provides support for treating payloads and namespaces as
11-- | Provides support for treating payloads and namespaces as
12-- composable contexts. The common pattern would be to provide a
12-- composable contexts. The common pattern would be to provide a
13−-- 'KatipContext' instance for your base monad. When your program
13+-- 'KatipContext' instance for your base monad.
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
18module Katip.Monadic
14module Katip.Monadic
20 -- * Monadic variants of logging functions from "Katip.Core"
16 -- * Monadic variants of logging functions from "Katip.Core"
@@ -29,10 +25,10 @@ module Katip.Monadic
29 , LogContexts
25 , LogContexts
30 , liftPayload
26 , liftPayload
32− -- * LogT - Utility transformer that provides Katip and KatipContext instances
28+ -- * KatipContextT - Utility transformer that provides Katip and KatipContext instances
33− , LogT(..)
29+ , KatipContextT(..)
34− , runLogT
30+ , runKatipContextT
35− , LogTState(..)
31+ , KatipContextTState(..)
@@ -101,7 +97,7 @@ liftPayload = LogContexts . (:[]) . AnyLogContext
101-------------------------------------------------------------------------------
97-------------------------------------------------------------------------------
102-- | A monadic context that has an inherant way to get logging
98-- | A monadic context that has an inherant way to get logging
103-- context and namespace. Examples include a web application monad or
99-- context and namespace. Examples include a web application monad or
104−-- database monad. Combine with 'LogT' to nest.
100+-- database monad.
105class Katip m => KatipContext m where
101class Katip m => KatipContext m where
106 getKatipContext :: m LogContexts
102 getKatipContext :: m LogContexts
107 getKatipNamespace :: m Namespace
103 getKatipNamespace :: m Namespace
@@ -202,12 +198,12 @@ logExceptionM action sev = action `catchAll` \e -> f e >> throwM e
202-- le <- getLogEnv
198-- le <- getLogEnv
203-- ctx <- getKatipContext
199-- ctx <- getKatipContext
204-- ns <- getKatipNamespace
200-- ns <- getKatipNamespace
205−-- forkIO $ runLogT le ctx ns $ do
201+-- forkIO $ runKatipContextT le ctx ns $ do
206-- $(logTM) InfoS "Look, I can log in IO and retain context!"
202-- $(logTM) InfoS "Look, I can log in IO and retain context!"
207-- doOtherStuff
203-- doOtherStuff
209−newtype LogT m a = LogT {
205+newtype KatipContextT m a = KatipContextT {
210− unLogT :: ReaderT LogTState m a
206+ unKatipContextT :: ReaderT KatipContextTState m a
211 } deriving ( Functor
207 } deriving ( Functor
212 , Applicative
208 , Applicative
@@ -226,30 +222,30 @@ newtype LogT m a = LogT {
229−data LogTState = LogTState {
225+data KatipContextTState = KatipContextTState {
230 ltsLogEnv :: !LogEnv
226 ltsLogEnv :: !LogEnv
231 , ltsContext :: !LogContexts
227 , ltsContext :: !LogContexts
232 , ltsNamespace :: !Namespace
228 , ltsNamespace :: !Namespace
235-- Reader is a passthrough. We don't expose our internal reader so as not to conflict
231-- 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
237 ask = lift ask
233 ask = lift ask
238− local f (LogT (ReaderT m)) = LogT $ ReaderT $ \r ->
234+ local f (KatipContextT (ReaderT m)) = KatipContextT $ ReaderT $ \r ->
239 local f (m r)
235 local f (m r)
242−instance (MonadIO m) => Katip (LogT m) where
238+instance (MonadIO m) => Katip (KatipContextT m) where
243− getLogEnv = LogT $ ReaderT $ \lts -> return (ltsLogEnv lts)
239+ getLogEnv = KatipContextT $ ReaderT $ \lts -> return (ltsLogEnv lts)
246−instance (MonadIO m) => KatipContext (LogT m) where
242+instance (MonadIO m) => KatipContext (KatipContextT m) where
247− getKatipContext = LogT $ ReaderT $ \lts -> return (ltsContext lts)
243+ getKatipContext = KatipContextT $ ReaderT $ \lts -> return (ltsContext lts)
248− getKatipNamespace = LogT $ ReaderT $ \lts -> return (ltsNamespace lts)
244+ getKatipNamespace = KatipContextT $ ReaderT $ \lts -> return (ltsNamespace lts)
251-------------------------------------------------------------------------------
247-------------------------------------------------------------------------------
252−runLogT :: (LogItem c) => LogEnv -> c -> Namespace -> LogT m a -> m a
248+runKatipContextT :: (LogItem c) => LogEnv -> c -> Namespace -> KatipContextT m a -> m a
253−runLogT le ctx ns = flip runReaderT lts . unLogT
249+runKatipContextT le ctx ns = flip runReaderT lts . unKatipContextT
255− lts = LogTState le (liftPayload ctx) ns
251+ lts = KatipContextTState le (liftPayload ctx) ns