log-warper-1.9.0: Flexible, configurable, monadic and pretty logging

Safe HaskellNone
LanguageHaskell2010

System.Wlog.CanLog

Contents

Description

Type class that add ability to log messages. Supports pure and IO logging.

Synopsis

Documentation

class Monad m => CanLog m where Source #

Instances of this class should explain how they add messages to their log.

Minimal complete definition

Nothing

Methods

dispatchMessage :: LoggerName -> Severity -> Text -> m () Source #

dispatchMessage :: (MonadTrans t, t n ~ m, CanLog n) => LoggerName -> Severity -> Text -> m () Source #

Instances
CanLog IO Source # 
Instance details

Defined in System.Wlog.CanLog

CanLog m => CanLog (LoggerNameBox m) Source # 
Instance details

Defined in System.Wlog.CanLog

Monad m => CanLog (NamedPureLogger m) Source # 
Instance details

Defined in System.Wlog.PureLogging

Monad m => CanLog (PureLogger m) Source # 
Instance details

Defined in System.Wlog.PureLogging

CanLog m => CanLog (StateT s m) Source # 
Instance details

Defined in System.Wlog.CanLog

CanLog m => CanLog (StateT s m) Source # 
Instance details

Defined in System.Wlog.CanLog

CanLog m => CanLog (ExceptT s m) Source # 
Instance details

Defined in System.Wlog.CanLog

CanLog m => CanLog (ReaderT r m) Source # 
Instance details

Defined in System.Wlog.CanLog

(CanLog m, Monoid w) => CanLog (RWST r w s m) Source # 
Instance details

Defined in System.Wlog.CanLog

Methods

dispatchMessage :: LoggerName -> Severity -> Text -> RWST r w s m () Source #

(CanLog m, Monoid w) => CanLog (RWST r w s m) Source # 
Instance details

Defined in System.Wlog.CanLog

Methods

dispatchMessage :: LoggerName -> Severity -> Text -> RWST r w s m () Source #

type WithLogger m = (CanLog m, HasLoggerName m) Source #

Type alias for constraints CanLog and HasLoggerName. We need two different type classes to support more flexible interface but in practice we usually use them both.

type WithLoggerIO m = (MonadIO m, WithLogger m) Source #

Type alias for constraints WithLogger and MonadIO. It is a very common situation to use both of them together.

Logging functions

logDebug :: WithLogger m => Text -> m () Source #

Shortcut for logMessage to use according severity.

logError :: WithLogger m => Text -> m () Source #

Shortcut for logMessage to use according severity.

logInfo :: WithLogger m => Text -> m () Source #

Shortcut for logMessage to use according severity.

logNotice :: WithLogger m => Text -> m () Source #

Shortcut for logMessage to use according severity.

logWarning :: WithLogger m => Text -> m () Source #

Shortcut for logMessage to use according severity.

logMessage :: WithLogger m => Severity -> Text -> m () Source #

Logs message with specified severity using logger name in context.

liftLogIO :: WithLoggerIO m => (IO a -> IO b) -> LoggerNameBox IO a -> m b Source #

It's very common situation when we need to write log messages inside functions that work in IO.

To do so we need to configure logger name each time inside work of this function.

liftLogIO is the easiest way to deal with such kind of situations.

Usage Example

Expand

We have some function

clientStart :: HostName -> .. -> IO ClientComponentMap
clientStart hostName .. = do
    ...
    forkIO $ routeIncoming endPoint msgs
    ...

We need to log Error messages in routeIncoming function. To do that we firstly need clientStart to work in MonadIO

clientStart :: (MonadIO m) => HostName -> .. -> m ClientComponentMap
clientStart hostName .. = do
    ...
    liftIO $ forkIO $ routeIncoming endPoint msgs
    ...

After we added some logError into routeIncoming clientStart should now work in WithLogger. Thus we can use WithLoggerIO which is combination of MonadIO and WithLogger. Taking into consideration all above we get:

clientStart :: WithLoggerIO m => HostName -> .. -> m ClientComponentMap
clientStart hostName .. = do
    ...
    logName <- askLoggerName
    liftIO $ forkIO $ usingLoggerName logName $ routeIncoming endPoint msgs
    ...

So, here we see how useful this function can be.

clientStart :: WithLoggerIO m => HostName -> .. -> m ClientComponentMap
clientStart hostName .. = do
    ...
    liftLogIO forkIO $ routeIncoming endPoint msgs
    ...