Safe Haskell | None |
---|---|
Language | Haskell2010 |
A logging effect based on MonadLog
.
Synopsis
- data Logs message a where
- logMsg :: Member (Logs m) r => m -> Eff r ()
- interceptLogging :: forall r m a. Member (Logs m) r => (m -> Eff r ()) -> Eff r a -> Eff r a
- foldLogMessages :: forall r m a f. (Foldable f, Member (Logs m) r) => (m -> f m) -> Eff r a -> Eff r a
- module Control.Monad.Log
- captureLogs :: NFData message => Eff (Logs message ': r) a -> Eff r (a, Seq message)
- ignoreLogs :: forall message r a. Eff (Logs message ': r) a -> Eff r a
- handleLogsWith :: forall m r message a. (NFData message, Monad m, SetMember Lift (Lift m) r) => (message -> m ()) -> Eff (Logs message ': r) a -> Eff r a
- handleLogsWithLoggingTHandler :: forall m r message a. (Monad m, SetMember Lift (Lift m) r) => Eff (Logs message ': r) a -> (forall b. (Handler m message -> m b) -> m b) -> Eff r a
- data LogChannel message
- logToChannel :: forall r message a. SetMember Lift (Lift IO) r => LogChannel message -> Eff (Logs message ': r) a -> Eff r a
- noLogger :: LogChannel message
- forkLogger :: forall message. (Typeable message, Show message) => Int -> (message -> IO ()) -> Maybe message -> IO (LogChannel message)
- filterLogChannel :: (message -> Bool) -> LogChannel message -> LogChannel message
- joinLogChannel :: (Show message, Typeable message) => Maybe message -> LogChannel message -> IO ()
- killLogChannel :: (Show message, Typeable message) => Maybe message -> LogChannel message -> IO ()
- closeLogChannelAfter :: (Show message, Typeable message, IsString message) => Maybe message -> LogChannel message -> IO a -> IO a
- logChannelBracket :: (Show message, Typeable message) => Int -> Maybe message -> Maybe message -> (LogChannel message -> IO a) -> LoggingT message IO a
- logChannelPutIO :: LogChannel message -> message -> IO ()
- data JoinLogChannelException m
- data KillLogChannelException m
Logging Effect
interceptLogging :: forall r m a. Member (Logs m) r => (m -> Eff r ()) -> Eff r a -> Eff r a Source #
Change, add or remove log messages and perform arbitrary actions upon intercepting a log message.
Requirements:
- All log meta data for typical prod code can be added without changing much of the code
- Add timestamp to a log messages of a sub-computation.
- Write some messages to a file.
- Log something extra, e.g. runtime memory usage in load tests
Approach: Install a callback that sneaks into to log message sending/receiving, to intercept the messages and execute some code and then return a new message.
foldLogMessages :: forall r m a f. (Foldable f, Member (Logs m) r) => (m -> f m) -> Eff r a -> Eff r a Source #
Intercept logging to change, add or remove log messages.
This is without side effects, hence faster than interceptLogging
.
module Control.Monad.Log
captureLogs :: NFData message => Eff (Logs message ': r) a -> Eff r (a, Seq message) Source #
Capture all log messages in a Seq
(strict).
ignoreLogs :: forall message r a. Eff (Logs message ': r) a -> Eff r a Source #
Throw away all log messages.
handleLogsWith :: forall m r message a. (NFData message, Monad m, SetMember Lift (Lift m) r) => (message -> m ()) -> Eff (Logs message ': r) a -> Eff r a Source #
Handle the Logs
effect with a monadic call back function (strict).
handleLogsWithLoggingTHandler :: forall m r message a. (Monad m, SetMember Lift (Lift m) r) => Eff (Logs message ': r) a -> (forall b. (Handler m message -> m b) -> m b) -> Eff r a Source #
Concurrent Logging
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.
logToChannel :: forall r message a. SetMember Lift (Lift IO) r => LogChannel message -> Eff (Logs message ': r) a -> Eff r a Source #
Send the log messages to a LogChannel
.
noLogger :: LogChannel message Source #
Create a LogChannel
that will discard all messages sent
via forwardLogstochannel
or logChannelPutIO
.
:: (Typeable message, Show message) | |
=> Int | Size of the log message input queue. If the queue is full, message are dropped silently. |
-> (message -> IO ()) | An IO action to log the messages |
-> Maybe message | Optional first message to log |
-> IO (LogChannel message) |
Fork a new process, that applies a monadic action to all log messages sent
via logToChannel
or logChannelPutIO
.
filterLogChannel :: (message -> Bool) -> LogChannel message -> LogChannel message Source #
Filter logs sent to a LogChannel
using a predicate.
joinLogChannel :: (Show message, Typeable message) => Maybe message -> LogChannel message -> IO () Source #
Close a log channel created by e.g. forkLogger
. Message already enqueue
are handled, as well as an optional final message. Subsequent log message
will not be handled anymore. If the log channel must be closed immediately,
use killLogChannel
instead.
killLogChannel :: (Show message, Typeable message) => Maybe message -> LogChannel message -> IO () Source #
Close a log channel quickly, without logging messages already in the queue.
Subsequent logging requests will not be handled anymore. If the log channel
must be closed without loosing any messages, use joinLogChannel
instead.
closeLogChannelAfter :: (Show message, Typeable message, IsString message) => Maybe message -> LogChannel message -> IO a -> IO a Source #
Run an action and close a LogChannel
created by noLogger
, forkLogger
or filterLogChannel
afterwards using joinLogChannel
. If a
SomeException
was thrown, the log channel is killed with
killLogChannel
, and the exception is re-thrown.
:: (Show message, Typeable message) | |
=> Int | Size of the log message input queue. If the queue is full, message are dropped silently. |
-> Maybe message | Optional first message to log |
-> Maybe message | Optional last message to log |
-> (LogChannel message -> IO a) | An IO action that will use the
|
-> LoggingT message IO a |
Wrap LogChannel
creation and destruction around a monad action in
bracket
y manner. This function uses joinLogChannel
, so en-queued messages
are flushed on exit. The resulting action is a LoggingT
action, which
is essentially a reader for a log handler function in IO
.
logChannelPutIO :: LogChannel message -> message -> IO () Source #
Enqueue a log message into a log channel
Internals
data JoinLogChannelException m Source #
Internal exception to shutdown a LogChannel
process created by
forkLogger
. This exception is handled such that all message already
en-queued are handled and then an optional final message is written.
Instances
Show m => Show (JoinLogChannelException m) Source # | |
Defined in Control.Eff.Log showsPrec :: Int -> JoinLogChannelException m -> ShowS # show :: JoinLogChannelException m -> String # showList :: [JoinLogChannelException m] -> ShowS # | |
(Typeable m, Show m) => Exception (JoinLogChannelException m) Source # | |
Defined in Control.Eff.Log |
data KillLogChannelException m Source #
Internal exception to **immediately** shutdown a LogChannel
process
created by forkLogger
, other than JoinLogChannelException
the message queue
will not be flushed, not further messages will be logged, except for the
optional final message.
Instances
Show m => Show (KillLogChannelException m) Source # | |
Defined in Control.Eff.Log showsPrec :: Int -> KillLogChannelException m -> ShowS # show :: KillLogChannelException m -> String # showList :: [KillLogChannelException m] -> ShowS # | |
(Typeable m, Show m) => Exception (KillLogChannelException m) Source # | |
Defined in Control.Eff.Log |