freer-extras-1.2.0.0: Useful extensions to simple-freer
Safe HaskellNone
LanguageHaskell2010

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

Associated Types

type Rep LogLevel :: Type -> Type Source #

ToJSON LogLevel Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

Methods

toJSON :: LogLevel -> Value

toEncoding :: LogLevel -> Encoding

toJSONList :: [LogLevel] -> Value

toEncodingList :: [LogLevel] -> Encoding

FromJSON LogLevel Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

Methods

parseJSON :: Value -> Parser LogLevel

parseJSONList :: Value -> Parser [LogLevel]

Pretty LogLevel Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

Methods

pretty :: LogLevel -> Doc ann

prettyList :: [LogLevel] -> Doc ann

type Rep LogLevel Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

type Rep LogLevel = D1 ('MetaData "LogLevel" "Control.Monad.Freer.Extras.Log" "freer-extras-1.2.0.0-1q4AUo79Td5ISTeTXorMWT" 'False) (((C1 ('MetaCons "Debug" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Info" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Notice" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Warning" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "Error" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Critical" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Alert" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Emergency" 'PrefixI 'False) (U1 :: Type -> Type))))

data LogMessage a Source #

Constructors

LogMessage 

Instances

Instances details
Functor LogMessage Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

Methods

fmap :: (a -> b) -> LogMessage a -> LogMessage b Source #

(<$) :: a -> LogMessage b -> LogMessage a Source #

Foldable LogMessage Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

Methods

fold :: Monoid m => LogMessage m -> m Source #

foldMap :: Monoid m => (a -> m) -> LogMessage a -> m Source #

foldMap' :: Monoid m => (a -> m) -> LogMessage a -> m Source #

foldr :: (a -> b -> b) -> b -> LogMessage a -> b Source #

foldr' :: (a -> b -> b) -> b -> LogMessage a -> b Source #

foldl :: (b -> a -> b) -> b -> LogMessage a -> b Source #

foldl' :: (b -> a -> b) -> b -> LogMessage a -> b Source #

foldr1 :: (a -> a -> a) -> LogMessage a -> a Source #

foldl1 :: (a -> a -> a) -> LogMessage a -> a Source #

toList :: LogMessage a -> [a] Source #

null :: LogMessage a -> Bool Source #

length :: LogMessage a -> Int Source #

elem :: Eq a => a -> LogMessage a -> Bool Source #

maximum :: Ord a => LogMessage a -> a Source #

minimum :: Ord a => LogMessage a -> a Source #

sum :: Num a => LogMessage a -> a Source #

product :: Num a => LogMessage a -> a Source #

Traversable LogMessage Source # 
Instance details

Defined in Control.Monad.Freer.Extras.Log

Methods

traverse :: Applicative f => (a -> f b) -> LogMessage a -> f (LogMessage b) Source #

sequenceA :: Applicative f => LogMessage (f a) -> f (LogMessage a) Source #

mapM :: Monad m => (a -> m b) -> LogMessage a -> m (LogMessage b) Source #

sequence :: Monad m => LogMessage (m a) -> m (LogMessage a) Source #

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 #

Methods

from :: LogMessage a -> Rep (LogMessage a) x Source #

to :: Rep (LogMessage a) x -> LogMessage a Source #

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

Defined in Control.Monad.Freer.Extras.Log

Methods

toJSON :: LogMessage a -> Value

toEncoding :: LogMessage a -> Encoding

toJSONList :: [LogMessage a] -> Value

toEncodingList :: [LogMessage a] -> Encoding

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

Defined in Control.Monad.Freer.Extras.Log

Methods

parseJSON :: Value -> Parser (LogMessage a)

parseJSONList :: Value -> Parser [LogMessage a]

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

Defined in Control.Monad.Freer.Extras.Log

Methods

pretty :: LogMessage a -> Doc ann

prettyList :: [LogMessage a] -> Doc ann

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-1q4AUo79Td5ISTeTXorMWT" 'False) (C1 ('MetaCons "LogMessage" 'PrefixI 'True) (S1 ('MetaSel ('Just "_logLevel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 LogLevel) :*: S1 ('MetaSel ('Just "_logMessageContent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 a)))

logLevel :: forall a. Lens' (LogMessage a) LogLevel Source #

logMessageContent :: forall a a. Lens (LogMessage a) (LogMessage a) a a Source #

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

  • obsLabelStart :: v

    Call-site information about the start of the observation

  • obsStart :: s

    Measurement taken before running the action

  • obsLabelEnd :: Maybe v

    Call-site information about the end of the observation

  • obsExit :: ExitMode

    ExitMode of the action.

observeBefore :: forall a. forall effs. Member (LogObserve a) effs => a -> Eff effs ObservationHandle Source #

observeAfter :: forall a. forall effs. Member (LogObserve a) effs => Maybe a -> ObservationHandle -> Eff effs () Source #

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.