freer-extras-1.2.0.0: Useful extensions to simple-freer
Safe Haskell None
Language Haskell2010

Control.Monad.Freer.Extras.Log

Synopsis

Documentation

This module provides effects and handlers for structured logging and tracing.

data LogMsg a r where Source #

Constructors

LMessage :: LogMessage a -> LogMsg a ()

data LogLevel Source #

The severity level of a log message See https://en.wikipedia.org/wiki/Syslog#Severity_level

Instances

Instances details
Eq LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Ord LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Show LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Generic LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

ToJSON LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

FromJSON LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Pretty LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

type Rep LogLevel Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

data LogMessage a Source #

Instances

Instances details
Functor LogMessage Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Foldable LogMessage Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Traversable LogMessage Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Eq a => Eq ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Ord a => Ord ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Show a => Show ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Generic ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Associated Types

type Rep ( LogMessage a) :: Type -> Type Source #

ToJSON a => ToJSON ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

FromJSON a => FromJSON ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

Pretty a => Pretty ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

type Rep ( LogMessage a) Source #
Instance details

Defined in Control.Monad.Freer.Extras.Log

type Rep ( LogMessage a) = D1 (' MetaData "LogMessage" "Control.Monad.Freer.Extras.Log" "freer-extras-1.2.0.0-LXgx2kLJeQTLxOMFH7LYd8" ' False ) ( C1 (' MetaCons "LogMessage" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "_logLevel") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedStrict ) ( Rec0 LogLevel ) :*: S1 (' MetaSel (' Just "_logMessageContent") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedStrict ) ( Rec0 a)))

logDebug :: forall a effs. Member ( LogMsg a) effs => a -> Eff effs () Source #

logInfo :: forall a effs. Member ( LogMsg a) effs => a -> Eff effs () Source #

logWarn :: forall a effs. Member ( LogMsg a) effs => a -> Eff effs () Source #

logError :: forall a effs. Member ( LogMsg a) effs => a -> Eff effs () Source #

Modifying logs

mapLog :: forall a b effs. Member ( LogMsg b) effs => (a -> b) -> LogMsg a ~> Eff effs Source #

Re-interpret a logging effect by mapping the log messages. (Does the same thing as contramap for Trace )

mapMLog :: forall a b effs. Member ( LogMsg b) effs => (a -> Eff effs b) -> LogMsg a ~> Eff effs Source #

Re-interpret a logging effect by mapping the log messages. Can use other effects.

Running logs

handleWriterLog :: forall a f effs. ( Member ( LogMsg a) effs, Traversable f) => (a -> LogLevel ) -> Eff ( Writer (f a) ': effs) ~> Eff effs Source #

Re-interpret a Writer effect by writing the events to the log

handleLogIgnore :: Eff ( LogMsg a ': effs) ~> Eff effs Source #

Ignore all log messages.

handleLogTrace :: Pretty a => Eff ( LogMsg a ': effs) ~> Eff effs Source #

Write the log to stdout using trace

handleLogWriter :: forall a w effs. Member ( Writer w) effs => AReview w ( LogMessage a) -> LogMsg a ~> Eff effs Source #

Re-interpret a Log effect with a Writer

renderLogMessages :: forall a effs. ( Member ( LogMsg Text ) effs, Pretty a) => LogMsg a ~> Eff effs Source #

Pretty-print the log messages

Observing

data ObservationHandle Source #

An abstract type used to tie the beginning and end of observations together.

data Observation v s Source #

An observation with measurements before and after running an action.

Constructors

Observation

Fields

Combinators

surround :: forall v a effs. Member ( LogObserve v) effs => v -> Eff effs a -> Eff effs a Source #

Write a log message before and after an action. Consider using observeBefore and observeAfter directly if you need more control over the values that are observed at the call site.

surroundDebug :: Member ( LogObserve ( LogMessage v)) effs => v -> Eff effs a -> Eff effs a Source #

surroundDebug = surround Debug

surroundInfo :: Member ( LogObserve ( LogMessage v)) effs => v -> Eff effs a -> Eff effs a Source #

surroundInfo = surround Info

surroundWarn :: Member ( LogObserve ( LogMessage v)) effs => v -> Eff effs a -> Eff effs a Source #

surroundWarn = surround Warn

Handlers

handleObserveLog :: forall effs. Member ( LogMsg Text ) effs => Eff ( LogObserve ( LogMessage Text ) ': effs) ~> Eff effs Source #

Interpret the LogObserve effect by logging a "start" message before the action and an "end" message after the action.

handleObserve Source #

Arguments

:: forall v s effs. (v -> Eff effs s)

How to get the current s

-> ( Observation v s -> Eff effs ())
-> Eff ( LogObserve v ': effs) ~> Eff effs

Handle the LogObserve effect by recording observations s before and after the observed action, and turning them into 'LogMessage (Observation s)' values.