Safe Haskell | None |
---|---|
Language | Haskell2010 |
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, LogMessage
s 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
.
LogPredicate
s
Synopsis
- module Control.Eff.Log.Handler
- module Control.Eff.Log.Message
- module Control.Eff.Log.Channel
- module Control.Eff.Log.Writer
- exampleLogging :: IO ()
- exampleWithLogging :: IO ()
- exampleWithSomeLogging :: ()
- exampleLogPredicate :: IO Int
- exampleLogCapture :: IO ()
- exampleAsyncLogging :: IO ()
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 LogWriter
s
module Control.Eff.Log.Handler
The module that contains the LogMessage
and LogPredicate
definitions.
The log message type corresponds to RFC-5424, including structured data.
module Control.Eff.Log.Message
This module only exposes a LogWriter
for asynchronous logging;
module Control.Eff.Log.Channel
This module defines the LogWriter
type, which is used to give
callback functions for log messages an explicit type.
module Control.Eff.Log.Writer
Example Code for Logging
exampleLogging :: IO () Source #
exampleWithLogging :: IO () Source #
Example code for:
exampleWithSomeLogging :: () Source #
Example code for:
exampleLogCapture :: IO () Source #
Example code for:
exampleAsyncLogging :: IO () Source #
Example code for: