| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.Wlog.CanLog
Description
Type class that add ability to log messages. Supports pure and IO logging.
- class Monad m => CanLog m where
- type WithLogger m = (CanLog m, HasLoggerName m)
- memoryLogs :: MVar (Maybe LogMemoryQueue)
- readMemoryLogs :: MonadIO m => m [Text]
- newtype PureLogger m a = PureLogger {
- runPureLogger :: WriterT (DList LogEvent) m a
- data LogEvent = LogEvent {
- leLoggerName :: !LoggerName
- leSeverity :: !Severity
- leMessage :: !Text
- dispatchEvents :: WithLogger m => [LogEvent] -> m ()
- runPureLog :: Monad m => PureLogger m a -> m (a, [LogEvent])
- logDebug :: WithLogger m => Text -> m ()
- logError :: WithLogger m => Text -> m ()
- logInfo :: WithLogger m => Text -> m ()
- logNotice :: WithLogger m => Text -> m ()
- logWarning :: WithLogger m => Text -> m ()
- logMessage :: WithLogger m => Severity -> Text -> m ()
Documentation
class Monad m => CanLog m where Source #
Instances of this class should explain how they add messages to their log.
Methods
dispatchMessage :: LoggerName -> Severity -> Text -> m () Source #
dispatchMessage :: (MonadTrans t, t n ~ m, CanLog n) => LoggerName -> Severity -> Text -> t n () Source #
Instances
| CanLog IO Source # | |
| CanLog m => CanLog (LoggerNameBox m) Source # | |
| Monad m => CanLog (PureLogger m) Source # | |
| CanLog m => CanLog (StateT s m) Source # | |
| CanLog m => CanLog (ExceptT s m) Source # | |
| CanLog m => CanLog (ReaderT * r m) Source # | |
| (CanLog m, Monoid w) => CanLog (RWST r w s m) Source # | |
| (CanLog m, Monoid w) => CanLog (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.
memoryLogs :: MVar (Maybe LogMemoryQueue) Source #
readMemoryLogs :: MonadIO m => m [Text] Source #
Retrieves memory logs in reversed order (newest are head).
Pure logging manipulation
newtype PureLogger m a Source #
Pure implementation of CanLog type class. Instead of writing log messages
into console it appends log messages into WriterT log. It uses DList for
better performance, because messages can be added only at the end of log.
But it uses unsafePerformIO so use with caution within IO.
TODO: Should we use some Data.Tree-like structure to observe message only
by chosen logger names?
Constructors
| PureLogger | |
Fields
| |
Instances
| MonadTrans PureLogger Source # | |
| MonadState s m => MonadState s (PureLogger m) Source # | |
| MonadReader r m => MonadReader r (PureLogger m) Source # | |
| MonadError e m => MonadError e (PureLogger m) Source # | |
| MonadBase b m => MonadBase b (PureLogger m) Source # | |
| Monad m => Monad (PureLogger m) Source # | |
| Functor m => Functor (PureLogger m) Source # | |
| Applicative m => Applicative (PureLogger m) Source # | |
| (HasLoggerName m, Monad m) => HasLoggerName (PureLogger m) Source # | |
| Monad m => CanLog (PureLogger m) Source # | |
| Monad m => MonadWriter (DList LogEvent) (PureLogger m) Source # | |
Holds all required information for dispatchLoggerName function.
Constructors
| LogEvent | |
Fields
| |
dispatchEvents :: WithLogger m => [LogEvent] -> m () Source #
Logs all LogEvent's from given list. This function supposed to
be used after runPureLog.
runPureLog :: Monad m => PureLogger m a -> m (a, [LogEvent]) Source #
Return log of pure logging action as list of LogEvent.
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.