Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
This module contains utility functions for logging and mapping trace data.
Synopsis
- trMessage :: ( MonadIO m, HasPrivacyAnnotation a, HasSeverityAnnotation a) => Tracer m (LoggerName, LogObject a) -> Tracer m a
- trMessageText :: ( MonadIO m, ToText a, HasPrivacyAnnotation a, HasSeverityAnnotation a) => Tracer m (LoggerName, LogObject Text ) -> Tracer m a
- transformTextTrace :: ToText a => Trace IO Text -> Trace IO a
- stdoutTextTracer :: ( MonadIO m, ToText a) => Tracer m a
- traceWithExceptT :: Monad m => Tracer m ( Either e a) -> ExceptT e m a -> ExceptT e m a
- traceResult :: MonadUnliftIO m => Tracer m ( BracketLog' ( Either e r)) -> ExceptT e m r -> ExceptT e m r
- formatResultMsg :: ( Show e, IsList t, Item t ~ ( Text , v), Buildable v, Buildable r) => Text -> t -> BracketLog' ( Either e r) -> Builder
- formatResultMsgWith :: ( IsList t, Item t ~ ( Text , v), Buildable v) => (e -> Builder ) -> (r -> Builder ) -> Text -> t -> BracketLog' ( Either e r) -> Builder
- resultSeverity :: Severity -> BracketLog' ( Either e r) -> Severity
- type BracketLog = BracketLog' SomeResult
- data BracketLog' r
- newtype LoggedException e = LoggedException e
- bracketTracer :: MonadUnliftIO m => Tracer m BracketLog -> m a -> m a
- bracketTracer' :: MonadUnliftIO m => (r -> a) -> Tracer m ( BracketLog' a) -> m r -> m r
- produceTimings :: ( MonadUnliftIO m, MonadMask m) => (a -> Maybe (ctx, BracketLog )) -> Tracer m (ctx, DiffTime ) -> m ( Tracer m a)
- unliftIOTracer :: MonadIO m => Tracer IO a -> Tracer m a
- flatContramapTracer :: Monad m => (a -> Maybe b) -> Tracer m b -> Tracer m a
Conversions from BM framework
trMessage :: ( MonadIO m, HasPrivacyAnnotation a, HasSeverityAnnotation a) => Tracer m (LoggerName, LogObject a) -> Tracer m a Source #
Tracer transformer which converts 'Trace m a' to 'Tracer m a' by wrapping
typed log messages into a
LogObject
.
trMessageText :: ( MonadIO m, ToText a, HasPrivacyAnnotation a, HasSeverityAnnotation a) => Tracer m (LoggerName, LogObject Text ) -> Tracer m a Source #
Formatting typed messages as plain text
Logging helpers
traceWithExceptT :: Monad m => Tracer m ( Either e a) -> ExceptT e m a -> ExceptT e m a Source #
Run an
ExceptT
action, then trace its result, all in one step.
This is a more basic version of
resultTracer
.
traceResult :: MonadUnliftIO m => Tracer m ( BracketLog' ( Either e r)) -> ExceptT e m r -> ExceptT e m r Source #
Log around an
ExceptT
action. The result of the action is captured as an
Either
in the log message. Other unexpected exceptions are captured in the
BracketLog'
.
:: ( Show e, IsList t, Item t ~ ( Text , v), Buildable v, Buildable r) | |
=> Text |
Function name. |
-> t |
Input parameters. |
-> BracketLog' ( Either e r) |
Logging around function. |
-> Builder |
Format a tracer message from
traceResult
as multiline text.
:: ( IsList t, Item t ~ ( Text , v), Buildable v) | |
=> (e -> Builder ) |
Error message formatter |
-> (r -> Builder ) |
Result formatter |
-> Text |
Function name. |
-> t |
Input parameters. |
-> BracketLog' ( Either e r) |
Logging around function. |
-> Builder |
Same as
formatResultMsg
, but accepts result formatters as parameters.
resultSeverity :: Severity -> BracketLog' ( Either e r) -> Severity Source #
A good default mapping of message severities for
traceResult
.
Logging and timing IO actions
type BracketLog = BracketLog' SomeResult Source #
Trace around an action, where the result doesn't matter.
data BracketLog' r Source #
Used for tracing around an action.
BracketStart |
Logged before the action starts. |
BracketFinish r |
Logged after the action finishes. |
BracketException ( LoggedException SomeException ) |
Logged when the action throws an exception. |
BracketAsyncException ( LoggedException SomeException ) |
Logged when the action receives an async exception. |
Instances
newtype LoggedException e Source #
Exception wrapper with typeclass instances that exception types often don't have.
Instances
bracketTracer :: MonadUnliftIO m => Tracer m BracketLog -> m a -> m a Source #
Run a monadic action with
BracketLog
traced around it.
:: MonadUnliftIO m | |
=> (r -> a) |
Transform value into log message. |
-> Tracer m ( BracketLog' a) |
Tracer. |
-> m r |
Action. |
-> m r |
Run a monadic action with
BracketLog
traced around it.
:: ( MonadUnliftIO m, MonadMask m) | |
=> (a -> Maybe (ctx, BracketLog )) |
Function to extract BracketLog messages from
|
-> Tracer m (ctx, DiffTime ) |
The timings tracer, has time deltas for each finished bracket. |
-> m ( Tracer m a) |
Simplified wrapper for
mkOutcomeExtractor
. This produces a timings
Tracer
from a
Tracer
of messages
a
, and a function which can extract
the
BracketLog
from
a
.
The extractor function can provide
ctx
, which could be the name of the
timed operation for example.
The produced tracer will make just one trace for each finished bracket.
It contains the
ctx
from the extractor and the time difference.
Tracer conversions
unliftIOTracer :: MonadIO m => Tracer IO a -> Tracer m a Source #
Convert an IO tracer to a
m
tracer.
flatContramapTracer :: Monad m => (a -> Maybe b) -> Tracer m b -> Tracer m a Source #
Conditional mapping of a
Tracer
.