contra-tracer-0.1.0.0: A simple interface for logging, tracing or monitoring.

Safe HaskellNone
LanguageHaskell2010

Control.Tracer

Contents

Description

Tracer is a contravariant functor to thread observable values through a number of transformers, possibly annotating them with additional information, or filtering them based on evaluating predicates.

Synopsis

Documentation

newtype Tracer m a Source #

example: simply output a message on the console

let logTrace = traceWith $ showTracing $ stdoutTracer
in  logTrace "hello world"

example: calling a function and passing in a Tracer

example1 :: IO ()
example1 = do
    let logTrace a = traceWith (showTracing (contramap ("Debug: " ++) stdoutTracer)) a
    void $ callFun1 logTrace
callFun1 :: (String -> IO ()) -> IO Int
callFun1 logTrace = do
    logTrace "in function 1"
    return 42

runTracer evaluates a Tracer (i.e. consumes its argument)

Constructors

Tracer 

Fields

Instances
Contravariant (Tracer m) Source # 
Instance details

Defined in Control.Tracer

Methods

contramap :: (a -> b) -> Tracer m b -> Tracer m a Source #

(>$) :: b -> Tracer m b -> Tracer m a Source #

Applicative m => Semigroup (Tracer m s) Source # 
Instance details

Defined in Control.Tracer

Methods

(<>) :: Tracer m s -> Tracer m s -> Tracer m s Source #

sconcat :: NonEmpty (Tracer m s) -> Tracer m s Source #

stimes :: Integral b => b -> Tracer m s -> Tracer m s Source #

Applicative m => Monoid (Tracer m s) Source # 
Instance details

Defined in Control.Tracer

Methods

mempty :: Tracer m s Source #

mappend :: Tracer m s -> Tracer m s -> Tracer m s Source #

mconcat :: [Tracer m s] -> Tracer m s Source #

tracing

traceWith :: Tracer m a -> a -> m () Source #

trace an observable value with a Tracer

tracers

nullTracer :: Applicative m => Tracer m a Source #

this Tracer forgets about all arguments

stdoutTracer :: MonadIO m => Tracer m String Source #

Output a traced String to stdout

debugTracer :: Applicative m => Tracer m String Source #

Output a traced String using Trace

transformers

showTracing :: Show a => Tracer m String -> Tracer m a Source #

transform a traced value to a showable instance.

condTracing :: Monad m => (a -> Bool) -> Tracer m a -> Tracer m a Source #

conditionally trace an observable given the evaluation of a predicate.

condTracingM :: Monad m => m (a -> Bool) -> Tracer m a -> Tracer m a Source #

conditionally trace an observable given the evaluation of a predicate in a monadic context.

natTracer :: (forall x. m x -> n x) -> Tracer m s -> Tracer n s Source #

natural transformation from monad m to monad n.