Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Tracer m a = Tracer (a -> m ())
- traceWith :: TraceWith x m => x a -> a -> m ()
- class HasEnumerableConstructors a
- invalidSilencedConstructors :: HasEnumerableConstructors a => Proxy a -> [String] -> [String]
- warnInvalidSilencedConstructorsWith :: (Applicative m, HasEnumerableConstructors a, IsString s) => Proxy a -> [String] -> Tracer m s -> m ()
- withSilencedTracer :: (Applicative m, HasEnumerableConstructors a) => [String] -> Tracer m a -> Tracer m a
- withAllowedTracer :: (Applicative m, HasEnumerableConstructors a) => [String] -> Tracer m a -> Tracer m a
- withMaybeTracer :: Applicative m => Tracer m a -> Tracer m (Maybe a)
- withEitherTracer :: Applicative m => Tracer m a -> Tracer m b -> Tracer m (Either a b)
- filterTracer :: Applicative m => (a -> Bool) -> Tracer m a -> Tracer m a
- simpleStdOutTracer :: MonadIO m => Tracer m String
- simpleStdErrTracer :: MonadIO m => Tracer m String
- voidTracer :: Applicative m => Tracer m t
- newtype IOTracer a = IOTracer (forall m. MonadIO m => Tracer m a)
Documentation
Tracer (a -> m ()) |
class HasEnumerableConstructors a Source #
Instances
invalidSilencedConstructors :: HasEnumerableConstructors a => Proxy a -> [String] -> [String] Source #
warnInvalidSilencedConstructorsWith :: (Applicative m, HasEnumerableConstructors a, IsString s) => Proxy a -> [String] -> Tracer m s -> m () Source #
Given a "string-like" tracer, outputs a warning message if the supplied silencedConstructors
do not
match the output of allConstructors
for the given tracer type a
withSilencedTracer :: (Applicative m, HasEnumerableConstructors a) => [String] -> Tracer m a -> Tracer m a Source #
Modifies a given tracer so that any message with a constructor name appearing in silencedConstructors
will be discarded. In order to work as expected, the type a
is required to have an automatically
derived instance of HasEnumerableConstructors
.
data Foo = Florb Int | Fleeb String | Bar Bool deriving (Generic, HasEnumerableConstructors)
then calling
> traceWith (withSilencedTracer [Bar] t) $ Bar False
is equivalent to
> pure ()
and
> traceWith (withSilencedTracer [Bar] t) $ Florb 3
will be definitionally equal to
> traceWith t $ Florb 3
withAllowedTracer :: (Applicative m, HasEnumerableConstructors a) => [String] -> Tracer m a -> Tracer m a Source #
The opposite of withSilencedTracer
. This tracer only loggs messages which match a constructor in
allowedConstructors
.
withMaybeTracer :: Applicative m => Tracer m a -> Tracer m (Maybe a) Source #
Turns a tracer for some a
into a tracer for 'Maybe a', which traces 'Just x' using the original tracer
| and ignores Nothing
(i.e. 'pure ()')
withEitherTracer :: Applicative m => Tracer m a -> Tracer m b -> Tracer m (Either a b) Source #
Takes two tracers for values a
and b
to a tracer for 'Either a b', which selects the appropriate tracer for each value
filterTracer :: Applicative m => (a -> Bool) -> Tracer m a -> Tracer m a Source #
voidTracer :: Applicative m => Tracer m t Source #
Tracer that discards/ignores all messages. Useful in test suites, if we don't care about logging output
To avoid having to write those pesky liftIO
s when changing monads, e.g. when
passing the logger into a servant server, we can hide the monad entirely behind an
existential, requiring a MonadIO
instance.
We wrap in newtype instead of just a type synonym, to avoid having to have
RankNTypes turned on everywhere.