So here’s the deal, I’m looking for a general purpose library that’s fast, structured, maintained, high-level and with a good documentation.
Now of course, I don’t expect the open source community to just provide a library with all these characteristics, I know I’ll have to write documentation, pull requests for missing features, etc, that’s fine I’m all in.
But searching on Hackage for even one or two of of these characteristics left me clueless.
There is fast-logger which seems to be the most downloaded on hackage, but it seems very low-level and impractical for app or web-server usage.
There is wai-logger but it seems quite specific to web servers.
And then there are many others with less downloads which all bring some specifics that are not directly related to what I’m seeking (mainly effects).
TL;DR what logging libraries do you use ? Are you happy with it ? What’s used in big haskell projects ?
So that’s the one I was thinking was the goto haskell library for logging initially, but it’s not downloaded much (not that I care too much about that specific metric, but It made me ponder).
Like @Kleidukos, I also suggest log-base (via log-effectful). There’s beauty in the simplicity behind it, there’s not a huge amount to it! I’m also the author of logging-effect: A mtl-style monad transformer for general purpose & compositional logging and I wanted to avocate structured logging there. Ultimately I find the API here a bit too cumbersome to work with, and prefer how log-base deals with this: log messages have text, and an optional blob of JSON.
monad-logger is based on fast-logger and provides some useful abstractions. It is used in Yesod. I like the type class approach that lets you decide later on how and where to collect the log messages.
That said, sometimes you can get quite far with just a WriterT [Text] and discharge the WriterT component as you see fit.
This advice applies only if you Know What You’re Doing. Otherwise it’s highly likely that you’ll make something that performs terribly and is not thread-safe. I’ve seen it a dozen times.
hmm I can’t even think of an application I’ve built where my logger performance matters enough that I can just spew to stderr with what’s in base
Only thread safety issue I can imagine is disabling line buffering?
I rolled a logger in IO that used an implicit param for context (that the user never touches - so no user-facing -XImplicitParams). Worked great, was easy to write an mtl shim for parts of the code that preferred that, spewed JSON to stderr.
The main issues I’ve run into with logs are downstream in aggregators like ES.
Oh I guess I ran into my logger crashing my games on Windows because there was no stderr. But traceIO does the Right Thing so that was an easy fix.
Besides, I don’t think it’s a very good vibe, community wise, to tell people to build their own libraries in this context. Not that I want to deter anyone from doing it, everyone’s free to enjoy any path towards success, but I don’t see it as a good answer to my question.
There are many good reasons for sharing code in libraries beyond “doing it myself is too hard”. And I don’t see any benefit/risk/cost ratio bending towards building it myself in this case.
I very much enjoy monad-logger-aeson, both on personal projects and professionally. It provides structured logging, it is fast (I think based on fast-logger), it is maintained, and it is well documented.