Created: 2023-01-26 22:01
Here’s a quick overview of some of the available logging libraries in Haskell.
Resources
- Thoughts on the logging framework and some more context in this Reddit post.
- Takeaways: log to stdout only and use OS/platform tools to collect and aggregate the logs (eg. ELK’s filebeat, or AWS CloudWatch)
- Should be fist and simple, the filtering, timestamps, etc. should be added by the aggregator
- These are the thoughts behind co-log-json
co-log
Low-ish level library for logging, implemented used some fancy patterns (like contravariant functors, divisible and decidable type classes).
As far a resources go, there’s a really nicely detailed post explaining the library features: Co-log: Composable contravariant combinatorial comonadic configurable convenient logging
And there’s a co-log-json library by the community.
I’m not sure how active is the maintenance of the library. For example GHC 9.4 isn’t supported yet. This was the case for other Kowainik libraries like their Prelude.
Example with Servant => https://github.com/kowainik/piece-of-cake-slayer
katip
A structured logging framework for Haskell. It’s one of the most established ones, has a good ecosystem of packages (like Logstash and ElasticSearch backents) => https://hackage.haskell.org/packages/search?terms=katip
Here’s an example that sets up Katip with servant https://github.com/parsonsmatt/servant-persistent (however it doesn’t use it in the application)
log-base
A library that provides a way to record structured log messages. Use this package in conjunction with ‘log-elasticsearch’ or ‘log-postgres’, depending on which back end you need.
This one looks pretty simple and supports ElasticShearch as a backend.
It also has a companion library to do WAI logging (wai-log)
logging-effect
MTL logging library, pretty unopinionated about the format of the messages, should be relatively easy to implement a JSON logger on top of this. Same as with co-log
.
monad-logger-aeson
structured JSON logging using monad-logger’s interface.
Announcing monad-logger-aeson: Structured logging in Haskell for cheap.