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

Safe HaskellNone
LanguageHaskell2010

Control.Eff.Log.Channel

Description

Concurrent Logging

Synopsis

Documentation

data LogChannel message Source #

A log channel processes logs from the Logs effect by en-queuing them in a shared queue read from a seperate processes. A channel can contain log message filters.

withAsyncLogChannel Source #

Arguments

:: (NFData message, Integral len) 
=> len

Size of the log message input queue. If the queue is full, message are dropped silently.

-> LogWriter message IO

An IO action to write the log messages

-> (LogChannel message -> IO a) 
-> IO a 

Fork a new process in which the given log message writer, will listen on a message queue in a LogChannel, which is passed to the second function. If the function returns or throws, the logging process will be killed.

Log messages are deeply evaluated before being sent to the logger process, to prevent that lazy evaluation leads to heavy work being done in the logger process instead of the caller process.

Example usage, a super stupid log to file:

main =
  withAsyncLogChannel
     1000
     (singleMessageLogWriter putStrLn)
     (handleLoggingAndIO
       (do logMsg "test 1"
           logMsg "test 2"
           logMsg "test 3"))

handleLoggingAndIO :: (NFData m, HasCallStack) => Eff '[Logs m, LogWriterReader m IO, Lift IO] a -> LogChannel m -> IO a Source #

Fork an IO based log writer thread and set the LogWriter to an action that will send all logs to that thread via a bounded queue. When the queue is full, flush it