-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Case use:
- Have “global” log action that is mutable at run time. For example, the default log action is at a low verbosity level at normal time, a system admin could switch to a higher verbosity level logs without having to restart a running server
- MVar allows another (admin) thread to change the default log action on the fly via the MVar
- Do not use any of the performUnsafeIO hacks
module Colog.Core.Action (hoistLogActionMVar , hoistLogActionIOMVar) where
import Colog (LogAction(..), hoistLogAction)
import Control.Concurrent.MVar (MVar, readMVar)
import Control.Monad.IO.Class (MonadIO(..))
hoistLogActionMVar :: MonadIO n => (forall a. m a -> n a) -> MVar (LogAction m msg) -> LogAction n msg
hoistLogActionMVar f v =
LogAction
\msg -> do
m <- liftIO $ readMVar v
unLogAction (hoistLogAction f m) msg
hoistLogActionIOMVar :: MonadIO m => MVar (LogAction IO msg) -> LogAction m msg
hoistLogActionIOMVar = hoistLogActionMVar liftIO
Every log action will involve additional IO (readMVar), performance impact not assessed.
Appreciate comments
alaendle
Metadata
Metadata
Assignees
Labels
No labels