co-log-0.4.0.1: Composable Contravariant Comonadic Logging Library
Copyright(c) 2018-2020 Kowainik
LicenseMPL-2.0
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Colog.Monad

Description

Core of the mtl implementation.

Synopsis

Documentation

newtype LoggerT msg m a Source #

newtype wrapper ReaderT that keeps LogAction in its context.

Constructors

LoggerT 

Fields

Instances

Instances details
MonadTrans (LoggerT msg) Source # 
Instance details

Defined in Colog.Monad

Methods

lift :: Monad m => m a -> LoggerT msg m a #

Monad m => Monad (LoggerT msg m) Source # 
Instance details

Defined in Colog.Monad

Methods

(>>=) :: LoggerT msg m a -> (a -> LoggerT msg m b) -> LoggerT msg m b #

(>>) :: LoggerT msg m a -> LoggerT msg m b -> LoggerT msg m b #

return :: a -> LoggerT msg m a #

Functor m => Functor (LoggerT msg m) Source # 
Instance details

Defined in Colog.Monad

Methods

fmap :: (a -> b) -> LoggerT msg m a -> LoggerT msg m b #

(<$) :: a -> LoggerT msg m b -> LoggerT msg m a #

Applicative m => Applicative (LoggerT msg m) Source # 
Instance details

Defined in Colog.Monad

Methods

pure :: a -> LoggerT msg m a #

(<*>) :: LoggerT msg m (a -> b) -> LoggerT msg m a -> LoggerT msg m b #

liftA2 :: (a -> b -> c) -> LoggerT msg m a -> LoggerT msg m b -> LoggerT msg m c #

(*>) :: LoggerT msg m a -> LoggerT msg m b -> LoggerT msg m b #

(<*) :: LoggerT msg m a -> LoggerT msg m b -> LoggerT msg m a #

MonadIO m => MonadIO (LoggerT msg m) Source # 
Instance details

Defined in Colog.Monad

Methods

liftIO :: IO a -> LoggerT msg m a #

Monad m => MonadReader (LogAction (LoggerT msg m) msg) (LoggerT msg m) Source # 
Instance details

Defined in Colog.Monad

Methods

ask :: LoggerT msg m (LogAction (LoggerT msg m) msg) #

local :: (LogAction (LoggerT msg m) msg -> LogAction (LoggerT msg m) msg) -> LoggerT msg m a -> LoggerT msg m a #

reader :: (LogAction (LoggerT msg m) msg -> a) -> LoggerT msg m a #

type WithLog env msg m = (MonadReader env m, HasLog env msg m, HasCallStack) Source #

Type alias for constraint for:

  1. Monad m have access to environment env.
  2. Environment env contains LogAction that can log messages of type msg.
  3. Function call stack.

If you use this constraint, function call stack will be propagated and you will have access to code lines that log messages.

logMsg :: forall msg env m. WithLog env msg m => msg -> m () Source #

Perform logging action with given message msg. This function works for monads that have access to LogAction.

You can use this function like this:

example :: WithLog env String m => m ()
example = do
    logMsg "First message..."
    logMsg "Second message..."

logMsgs :: forall msg env f m. (Foldable f, WithLog env msg m) => f msg -> m () Source #

Logs multiple messages.

withLog :: WithLog env msg m => (LogAction m msg -> LogAction m msg) -> m a -> m a Source #

Performs given monadic logging action by applying function to every logging record.

app :: WithLog env String m => m ()
app = withLog (cmap ("app:" ++)) $ do
    logMsg "First message..."
    logMsg "Second message..."

liftLogAction :: (Monad m, MonadTrans t) => LogAction m msg -> LogAction (t m) msg Source #

Lifts LogAction by allowing to log in a transformed monad.

usingLoggerT :: Monad m => LogAction m msg -> LoggerT msg m a -> m a Source #

Runner for LoggerT monad. Let's consider one simple example of monadic action you have:

app :: WithLog env String m => m ()
app = do
    logMsg "Starting application..."
    withLog (cmap ("app:" ++)) $ do
        logMsg "Application started."
        logMsg "Application finished."

You can use the following way of running such example:

usingLoggerT (LogAction putStrLn) app

And you will see this output:

Starting application...
app:Application started.
app:Application finished.