| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
System.Wlog.PureLogging
Contents
Description
This module supports pure logging.
Synopsis
- newtype PureLogger m a = PureLogger {
- runPureLogger :: StateT (Seq LogEvent) m a
 
 - data LogEvent = LogEvent {
- leLoggerName :: !LoggerName
 - leSeverity :: !Severity
 - leMessage :: !Text
 
 - dispatchEvents :: CanLog m => [LogEvent] -> m ()
 - logEvents :: WithLogger m => [LogEvent] -> m ()
 - runPureLog :: Functor m => PureLogger m a -> m (a, [LogEvent])
 - launchPureLog :: (CanLog n, Monad m) => (forall f. Functor f => m (f a) -> n (f b)) -> PureLogger m a -> n b
 - newtype NamedPureLogger m a = NamedPureLogger {
- runNamedPureLogger :: PureLogger (LoggerNameBox m) a
 
 - runNamedPureLog :: (Monad m, HasLoggerName m) => NamedPureLogger m a -> m (a, [LogEvent])
 - launchNamedPureLog :: (WithLogger n, Monad m) => (forall f. Functor f => m (f a) -> n (f b)) -> NamedPureLogger m a -> n b
 - launchNamedPureLogWith :: (WithLogger n, Monad m) => (forall f. Functor f => m (f a) -> f b) -> NamedPureLogger m a -> n b
 - usingNamedPureLogger :: Functor m => LoggerName -> NamedPureLogger m a -> m (a, [LogEvent])
 - logPureAction :: WithLogger m => NamedPureLogger m a -> m a
 
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 StateT 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
Holds all required information for dispatchLoggerName function.
Constructors
| LogEvent | |
Fields 
  | |
Instances
| Show LogEvent Source # | |
| Monad m => MonadState (Seq LogEvent) (NamedPureLogger m) Source # | |
Defined in System.Wlog.PureLogging  | |
| Monad m => MonadState (Seq LogEvent) (PureLogger m) Source # | |
Defined in System.Wlog.PureLogging  | |
dispatchEvents :: CanLog m => [LogEvent] -> m () Source #
Logs all LogEvent's from given list. This function supposed to
 be used after runPureLog.
logEvents :: WithLogger m => [LogEvent] -> m () Source #
Logs all LogEvent's from given list. Just like
 dispatchEvents but uses proper logger Name.
runPureLog :: Functor m => PureLogger m a -> m (a, [LogEvent]) Source #
Return log of pure logging action as list of LogEvent.
launchPureLog :: (CanLog n, Monad m) => (forall f. Functor f => m (f a) -> n (f b)) -> PureLogger m a -> n b Source #
Performs actual logging once given action completes.
newtype NamedPureLogger m a Source #
Constructors
| NamedPureLogger | |
Fields 
  | |
Instances
runNamedPureLog :: (Monad m, HasLoggerName m) => NamedPureLogger m a -> m (a, [LogEvent]) Source #
Return log of pure logging action as list of LogEvent,
 using logger name provided by context.
launchNamedPureLog :: (WithLogger n, Monad m) => (forall f. Functor f => m (f a) -> n (f b)) -> NamedPureLogger m a -> n b Source #
Similar to launchPureLog, but provides logger name from current context.
Running the NamedPureLogger gives us the pair  of target and the list of LogEvents,
wrapped in Monad from where using the fact that (,) is Functor logging can be triggered.
Example
  newtype PureSmth a = ...
      deriving (MonadSmth, ...)
  instance MonadSmth m => MonadSmt (NamedLoggerName m)
  evalPureSmth :: PureSmth a -> a
  makeField    :: MonadSmth m => Data -> m Field
  run :: (MonadIO m, WithLogger m) => m ()
  run = do
      data  <- getData
      -- field :: Field
      field <- launchNamedPureLog (pure . evalPureSmth) (makeField data)
      --       ^ logging happens here
      ...
launchNamedPureLogWith :: (WithLogger n, Monad m) => (forall f. Functor f => m (f a) -> f b) -> NamedPureLogger m a -> n b Source #
Similar to launchNamedPureLog, but calls pure on passed function result.
Example
The example from launchNamedPureLog with usage of this function will look like:
  newtype PureSmth a = ...
      deriving (MonadSmth, ...)
  instance MonadSmth m => MonadSmt (NamedLoggerName m)
  evalPureSmth :: PureSmth a -> a
  makeField    :: MonadSmth m => Data -> m Field
  run :: (MonadIO m, WithLogger m) => m ()
  run = do
      data  <- getData
      -- field :: Field
      field <- launchNamedPureLogWith evalPureSmth $ makeField data
      --       ^ logging happens here
      ...
usingNamedPureLogger :: Functor m => LoggerName -> NamedPureLogger m a -> m (a, [LogEvent]) Source #
Similar to runNamedPureLog, but using provided logger name.
logPureAction :: WithLogger m => NamedPureLogger m a -> m a Source #
Perform pure-logging computation, log its events and return the result of the computation