@@ -60,11 +60,11 @@ main = do
60 -- use this to stack up various contextual details throughout your
60 -- use this to stack up various contextual details throughout your
61 -- code and they will be flattened out and combined in the log
61 -- code and they will be flattened out and combined in the log
62 -- output.
62 -- output.
63− addNamespace "confrabulation" $ addContext (ConfrabLogCTX 42) $ do
63+ katipAddNamespace "confrabulation" $ katipAddContext (ConfrabLogCTX 42) $ do
64 $(logTM) DebugS "Confrabulating widgets, with extra namespace and context"
64 $(logTM) DebugS "Confrabulating widgets, with extra namespace and context"
65 confrabulateWidgets
65 confrabulateWidgets
66 $(logTM) InfoS "Namespace and context are back to normal"
66 $(logTM) InfoS "Namespace and context are back to normal"
67− noLogging $
67+ katipNoLogging $
68 $(logTM) DebugS "You'll never see this log message!"
68 $(logTM) DebugS "You'll never see this log message!"
69 -- This blocking call flushes all in-flight messages through
69 -- This blocking call flushes all in-flight messages through
70 -- handlers and then finalizes each scribe.
70 -- handlers and then finalizes each scribe.
@@ -118,31 +118,14 @@ instance MonadBaseControl b m => MonadBaseControl b (MyStack m) where
119instance (MonadIO m) => Katip (MyStack m) where
119instance (MonadIO m) => Katip (MyStack m) where
120 getLogEnv = view msLogEnv
120 getLogEnv = view msLogEnv
121+ localLogEnv f (MyStack m) = MyStack (local (over msLogEnv f) m)
123instance (MonadIO m) => KatipContext (MyStack m) where
124instance (MonadIO m) => KatipContext (MyStack m) where
124 getKatipContext = view msKContext
125 getKatipContext = view msKContext
126+ localKatipContext f (MyStack m) = MyStack (local (over msKContext f) m)
125 getKatipNamespace = view msKNamespace
127 getKatipNamespace = view msKNamespace
126−
128+ localKatipNamespace f (MyStack m) = MyStack (local (over msKNamespace f) m)
128−-------------------------------------------------------------------------------
129−-- | Merge some context into the log only for the given block
130−addContext :: (LogItem i, MonadReader r m, HasMyState r) => i -> m a -> m a
131−addContext i = local (\r -> r & msKContext <>~ ctxs)
133− ctxs = liftPayload i
136−-------------------------------------------------------------------------------
137−-- | Add a layer of namespace to the logs only for the given block
138−addNamespace :: (MonadReader r m, HasMyState r) => Namespace -> m a -> m a
139−addNamespace ns = local (\r -> r & msKNamespace <>~ ns)
142−-------------------------------------------------------------------------------
143−-- | Disable all log output temporarily
144−noLogging :: (MonadReader r m, HasMyState r) => m a -> m a
145−noLogging = local (\r -> r & msLogEnv %~ clearScribes)
148-------------------------------------------------------------------------------
131-------------------------------------------------------------------------------