An extensible log effect using extensible-effects https://github.com/greydot/log-effect

Latest on Hackage:1.0.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

MIT licensed by Tobias Florek, Lana Black
Maintained by Lana Black

Log effect

Build Status

An extensible log effect using extensible-effects. This library introduces two new effects to your extensible effects arsenal, Log and LogM. In short, if you’d like to add logging to pure code (that is, without Lift effect), Log is your best choice, otherwise go for LogM.


This is the simpler of the two. Log allows for logging in pure code, as well as filtering using filterLog. The downside of this effect is that when your code launches multiple threads using async or forkIO, messages from every thread other than the thread where the handler is run will be lost.


LogM loses the ability to provide logging in pure code, but at the same time allows to log messages from multiple threads.


import Control.Concurrent.Lifted
import Control.Eff
import Control.Eff.Lift
import Control.Eff.Log

someComp :: ( [ Log String, LogM IO String ] <:: r
            , LiftedBase IO r
            ) => Eff r ()
someComp = do logE "Hello!"
              logM "Greetings from the main thread!"
              _ <- fork $ do logM "This is a new thread, and this message is still visible."
                             logE "Unfortunately, this one is not."
              return ()

main :: IO ()
main = runLift $ runLog logger $ runLogM logger $ someComp
    -- Here we have to provide an explicit signature for our logger,
    -- because the compiler is unable to figure it out due to ambiguity.
    logger = stdoutLogger :: Logger IO String

See also

log-effect-syslog provides necessary types and functions to work with syslog.



Version 1.0

* Complete revamp of the logging effects.

* Add LogM effect.

* Add MonadBaseControl instances.

* Remove fast-logger dependency in favor of a custom typeclass.

Version 0.4

  • add a proxy to most runLog functions to not have to supply the full specialized type signature. Use something like data Proxy a = Proxy or the one from tagged.

  • remove ShowLog typeclass in favor of ToLogString from fast-logger.

comments powered byDisqus