log package:logging

Simplified logging in IO for application writers. logging is a wrapper around fast-logger which makes it easy to log from IO. It provides the following conveniences on top of those libraries:
  • A set of shorter functions to type: debug, log, warn, plus others that flush after each message, or which allow providing a message source string.
  • Logging variants of error, trace and traceShow, called errorL, traceL and traceShowL. These use unsafePerformIO in order to act as direct replacements, so the usual caveats apply.
  • A global function, setDebugLevel, which uses a global IORef to record the logging level, saving you from having to carry around the notion of "verbosity level" in a Reader environment.
  • A set of "timed" variants, timedLog and timedDebug, which report how long the specified action took to execute in wall-clock time.
The apostrophe varients of the logging functions flush the log after each message.
Quick example of how to use this module:
import Control.Logging

main = withStdoutLogging $ do
log "This is a log message!"
timedLog "This is a timed log message!" $ threadDelay 100000
Flush all collected logging messages. This is automatically called by withStdoutLogging and withStderrLogging when those blocks are exited by whatever means.
Set the verbosity level. Messages at our higher than this level are displayed. It defaults to LevelDebug.
Set the format used for log timestamps.
Output a logging message both before an action begins, and after it ends, reporting the total length of time. If an exception occurred, it is also reported.
Like timedLog, except that it does only logs when the action has completed or failed after it is done.
This function, or withStderrLogging, must be wrapped around whatever region of your application intends to use logging. Typically it would be wrapped around the body of main.