cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Logging

Description

This module contains utility functions for logging and mapping trace data.

Synopsis

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 #

Tracer transformer which transforms traced items to their ToText representation and further traces them as a LogObject . If the ToText representation is empty, then no tracing happens.

Formatting typed messages as plain text

transformTextTrace :: ToText a => Trace IO Text -> Trace IO a Source #

Converts a Text trace into any other type of trace that has a ToText instance.

stdoutTextTracer :: ( MonadIO m, ToText a) => Tracer m a Source #

Creates a tracer that prints any ToText log message. This is useful for debugging functions in the REPL, when you need a Tracer object.

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' .

formatResultMsg Source #

Arguments

:: ( 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.

formatResultMsgWith Source #

Arguments

:: ( 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.

Constructors

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

Instances details
Functor BracketLog' Source #
Instance details

Defined in Cardano.Wallet.Logging

MonadIO m => Outcome m ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

MonadIO m => Outcome m (ctx, BracketLog ) Source #
Instance details

Defined in Cardano.Wallet.Logging

Eq r => Eq ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Show r => Show ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Generic ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Associated Types

type Rep ( BracketLog' r) :: Type -> Type Source #

ToJSON r => ToJSON ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Buildable r => Buildable ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Buildable r => ToText ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

HasPrivacyAnnotation ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Methods

getPrivacyAnnotation :: BracketLog' r -> PrivacyAnnotation

HasSeverityAnnotation ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

Methods

getSeverityAnnotation :: BracketLog' r -> Severity

type Rep ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

type OutcomeMetric ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

type IntermediateValue ( BracketLog' r) Source #
Instance details

Defined in Cardano.Wallet.Logging

type OutcomeMetric (ctx, BracketLog ) Source #
Instance details

Defined in Cardano.Wallet.Logging

type IntermediateValue (ctx, BracketLog ) Source #
Instance details

Defined in Cardano.Wallet.Logging

newtype LoggedException e Source #

Exception wrapper with typeclass instances that exception types often don't have.

Constructors

LoggedException e

Instances

Instances details
Show e => Eq ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

( Show e, Ord e) => Ord ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

Show e => Show ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

Generic ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

NFData e => NFData ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

NFData ( LoggedException SomeException ) Source #
Instance details

Defined in Cardano.Wallet.Logging

Exception e => ToJSON ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

Exception e => Buildable ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

Exception e => ToText ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

type Rep ( LoggedException e) Source #
Instance details

Defined in Cardano.Wallet.Logging

type Rep ( LoggedException e) = D1 (' MetaData "LoggedException" "Cardano.Wallet.Logging" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "LoggedException" ' PrefixI ' False ) ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 e)))

bracketTracer :: MonadUnliftIO m => Tracer m BracketLog -> m a -> m a Source #

Run a monadic action with BracketLog traced around it.

bracketTracer' Source #

Arguments

:: 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.

produceTimings Source #

Arguments

:: ( MonadUnliftIO m, MonadMask m)
=> (a -> Maybe (ctx, BracketLog ))

Function to extract BracketLog messages from a , paired with context.

-> 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 .

Orphan instances

( MonadIO m, ToText a, HasPrivacyAnnotation a, HasSeverityAnnotation a) => Transformable Text m a Source #
Instance details

Methods

trTransformer :: TracingVerbosity -> Trace m Text -> Tracer m a