extensible-effects-concurrent-0.20.0: Message passing concurrency as extensible-effect

Safe HaskellNone
LanguageHaskell2010

Control.Eff.Log

Contents

Description

A logging effect.

There is just one log message type: LogMessage and it is written using logMsg and the functions built on top of it.

The Logs effect is tightly coupled with the LogWriterReader effect. When using the ControlMonadBaseControl instance, the underlying monad of the LogWriter, that is expected to be present through the respective LogWriterReader, is constrained to be the base monad itself, e.g. IO.

The log message type is fixed to LogMessage, and there is a type class for converting to that, call ToLogMessage.

There is a single global LogPredicate that can be used to suppress logs directly at the point where they are sent, in the logMsg function.

Note that all logging is eventually done via logMsg; logMsg is the only place where log filtering should happen.

Also, LogMessages are evaluated using deepseq, after they pass the LogPredicate, also inside logMsg.

Example:

exampleLogging :: IO ()
exampleLogging =
    runLift
  $ withLogging consoleLogWriter
  $ do
      logDebug "test 1.1"
      logError "test 1.2"
      censorLogs (prefixLogMessagesWith "NESTED: ")
       $ do
            addLogWriter debugTraceLogWriter
             $ setLogPredicate (\m -> (view lmMessage m) /= "not logged")
             $ do
                  logInfo "not logged"
                  logMsg "test 2.1"
            logWarning "test 2.2"
      logCritical "test 1.3"

Asynchronous Logging

Logging in a withAsync spawned thread is done using withAsyncLogging.

LogPredicates

See Control.Eff.Log.Handler

Synopsis

Module Re-Exports

This module contains the API for sending log messages and for handling the messages in the frame work of extensible effects.

It also defines the reader effect to access LogWriters

The module that contains the LogMessage and LogPredicate definitions.

The log message type corresponds to RFC-5424, including structured data.

This module only exposes a LogWriter for asynchronous logging;

This module defines the LogWriter type, which is used to give callback functions for log messages an explicit type.

Example Code for Logging