log-effect: An extensible log effect using extensible-effects

[ control, effect, library, logging, mit, program ] [ Propose Tags ]

Introduce two logging effects to your extensible effects arsenal


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.0.1, 0.2.0.2, 0.3.0.1, 0.3.0.2, 0.4.0.0, 0.4.0.1, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.2.0
Change log Changelog.md
Dependencies base (>=4.6 && <5.0), bytestring (>=0.10 && <0.11), extensible-effects (>=5.0.0.0 && <5.1.0.0), log-effect (==1.2.0), monad-control (>=1.0 && <1.1), text (>=1.2 && <1.3), transformers-base (>=0.4 && <0.5) [details]
License MIT
Author Tobias Florek, Lana Black
Maintainer Lana Black <lanablack@amok.cc>
Category Control, Effect, Logging
Home page https://github.com/greydot/log-effect
Source repo head: git clone https://github.com/greydot/log-effect
Uploaded by sickmind at 2019-03-02T00:05:59Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Executables log-example
Downloads 7028 total (33 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-03-02 [all 1 reports]

Readme for log-effect-1.2.0

[back to package description]

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.

Log

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

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

Example

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
  where
    -- 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.