Closed chshersh closed 6 years ago
Here I will describe plan to migrate to newer interface.
LoggerName
newtype LoggerNameBox m a = LoggerNameBox { loggerNameBoxEntry :: ReaderT LoggerName m a }
class HasLoggerName m where
askLoggerName :: m LoggerName
modifyLoggerName :: (LoggerName -> LoggerName) -> m a -> m a
class Monad m => CanLog m where
dispatchMessage :: LoggerName -> Severity -> Text -> m ()
instance CanLog IO where dispatchMessage = logM
{-# NOINLINE logInternalState #-}
logInternalState :: MVar LogInternalState
-- note: only kick up tree if handled locally
logInternalState = unsafePerformIO $ do ...
We probably want to switch to some another approach, for example: caps
. But at least LogInternalState
should be stored in ReaderT
context. Things become more complex because we want to support pure logging as well and we don't need LogInternalState
there.
So let's have:
newtype LoggerContext = ... -- old `LogInternalState`
newtype LoggerT m a = LoggerT { runLoggerT :: ReaderT (TVar LoggerContext) m a }
This will make transition more smooth. We are not going to remove all IO
functions, they just will work inside LoggerT
monad.
Here is the plan to do this:
LogInternalState
to LoggerContext
.LoggerT
newtype with all required derivings somewhere in its own module with LogInternalState
.IOLogger
to user LoggerT
type.IO
can no longer have CanLog
instance. Instead LoggerT
should have this instance implemented.buildAndSetupYamlLogging
.setupLogging
function cannot longer exist in a way it exists now. The only ways to run logging should be the following:
launchWithConfig
launchFromFile
launchSimpleLogging
Inside these functions we want to:TVar
with empty internal state which is here now (logInternalState
variable should be removed after that)setupLogging
which updates this TVar
TVar
after everything is finishedbracket
still should be usedProbably some technical details will arise during implementation..
Fixed in version 2.0.
Currently all IO configuration is done using global
MVar
withunsafePerformIO
. This is not really good :(