Hoogle Search
Within LTS Haskell 24.52 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
outputBaseThreadContext :: OutputOptions -> [Pair]monad-logger-aeson Control.Monad.Logger.Aeson Allows for setting a "base" thread context, i.e. a set of Pair that will always be present in log messages. If we subsequently use withThreadContext to register some thread context for our messages, if any of the keys in those Pair values overlap with the "base" thread context, then the overlapped Pair values in the "base" thread context will be overridden for the duration of the action provided to withThreadContext. Default: mempty
outputIncludeThreadId :: OutputOptions -> Boolmonad-logger-aeson Control.Monad.Logger.Aeson Controls whether or not the thread ID is included in each log message's thread context. Default: False
withThreadContext :: (MonadIO m, MonadMask m) => [Pair] -> m a -> m amonad-logger-aeson Control.Monad.Logger.Aeson This function lets us register structured, contextual info for the duration of the provided action. All messages logged within the provided action will automatically include this contextual info. This function is thread-safe, as the contextual info is scoped to the calling thread only. This function is additive: if we nest calls to it, each nested call will add to the existing thread context. In the case of overlapping keys, the nested call's Pair value(s) will win. Whenever the inner action completes, the thread context is rolled back to its value set in the enclosing action. If we wish to include the existing thread context from one thread in another thread, we must register the thread context explicitly on that other thread. myThreadContext can be leveraged in this case. Registering thread context for messages can be useful in many scenarios. One particularly apt scenario is in wai middlewares. We can generate an ID for each incoming request then include it in the thread context. Now all messages subsequently logged from our endpoint handler will automatically include that request ID:
import Control.Monad.Logger.Aeson ((.=), withThreadContext) import Network.Wai (Middleware) import qualified Data.UUID.V4 as UUID addRequestId :: Middleware addRequestId app = \request sendResponse -> do uuid <- UUID.nextRandom withThreadContext ["requestId" .= uuid] do app request sendResponse
If we're coming from a Java background, it may be helpful for us to draw parallels between this function and log4j2's ThreadContext (or perhaps log4j's MDC). They all enable the same thing: setting some thread-local info that will be automatically pulled into each logged message.logItemThreadContext :: LogItem -> KeyMap Valuemonad-logger-aeson Control.Monad.Logger.Aeson.Internal No documentation available.
loggedMessageThreadContext :: LoggedMessage -> KeyMap Valuemonad-logger-aeson Control.Monad.Logger.Aeson.Internal No documentation available.
outputBaseThreadContext :: OutputOptions -> [Pair]monad-logger-aeson Control.Monad.Logger.Aeson.Internal Allows for setting a "base" thread context, i.e. a set of Pair that will always be present in log messages. If we subsequently use withThreadContext to register some thread context for our messages, if any of the keys in those Pair values overlap with the "base" thread context, then the overlapped Pair values in the "base" thread context will be overridden for the duration of the action provided to withThreadContext. Default: mempty
outputIncludeThreadId :: OutputOptions -> Boolmonad-logger-aeson Control.Monad.Logger.Aeson.Internal Controls whether or not the thread ID is included in each log message's thread context. Default: False
threadContextStore :: Store (KeyMap Value)monad-logger-aeson Control.Monad.Logger.Aeson.Internal Thread-safe, global Store that captures the thread context of messages. Note that there is a bit of somewhat unavoidable name-overloading here: this binding is called threadContextStore because it stores the thread context (i.e. ThreadContext/MDC from Java land) for messages. It also just so happens that the Store type comes from the context package, which is a package providing thread-indexed storage of arbitrary context values. Please don't hate the player!
class Monad m =>
MonadReader (m :: Type -> Type)monads-tf Control.Monad.Reader See examples in Control.Monad.Reader. Note, the partially applied function type (->) r is a simple reader monad. See the instance declaration below.
mapReader :: (a -> b) -> Reader r a -> Reader r bmonads-tf Control.Monad.Reader Transform the value returned by a Reader.