Safe Haskell | None |
---|---|
Language | Haskell2010 |
Concurrent Logging
Synopsis
- data LogChannel message
- withAsyncLogChannel :: forall message a len. (NFData message, Integral len) => len -> LogWriter message IO -> (LogChannel message -> IO a) -> IO a
- handleLoggingAndIO :: (NFData m, HasCallStack) => Eff '[Logs m, LogWriterReader m IO, Lift IO] a -> LogChannel m -> IO a
- handleLoggingAndIO_ :: (NFData m, HasCallStack) => Eff '[Logs m, LogWriterReader m IO, Lift IO] a -> LogChannel m -> IO ()
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.
:: (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
handleLoggingAndIO_ :: (NFData m, HasCallStack) => Eff '[Logs m, LogWriterReader m IO, Lift IO] a -> LogChannel m -> IO () Source #
Like handleLoggingAndIO
but return ()
.