co-log-0.1.0: Logging library

Safe HaskellNone
LanguageHaskell2010

Colog.Monad

Synopsis

Documentation

newtype LoggerT msg m a Source #

newtype wrapper ReaderT that keeps LogAction in its context.

Constructors

LoggerT 

Fields

Instances
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 #

fail :: String -> 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 #

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 #

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.