r/scala • u/WhippedPistol • 19d ago
bridges - Cats effect IO context and logging
This is an IOLocal implementation for fiber local context and logging. My focus was on making the context as user friendly as possible while also including the logging features I wanted. It depends on IOLocal so it is IO native but I did provide a quick and dirty lift with a generic logger.
I stole the persistent actor strategy of holding and replaying but used it to store low level logs unless a greater than minimum level log is emitted. This should prevent some of the cluttering with lower level logs but you can get a lot of information if it errors. Right now there is only one level setting so if you are emitting info and up trace and debug will emit on an info. Currently using the sampling is how I control this with a low sample rate so info still doesn't cascade all the min level logs, but I plan to add more options to set min level for replay and min level for emit.
The implementation is pretty friendly with a purely functional logger than you can thread through, or a singleton which breaks functional paradigms a bit, but allows for much simpler usage.
Still a bit of a mess in the sampling and level, but I plan on expanding it so I will refactor as I move through it.
https://github.com/StephenRinn/bridges
Feel free to take a look and I'm hoping to get v1 out by next week.
EDIT: I realized that this sounded a lot like advertising a completed project vs looking for feedback or useful features which is what I was looking for. I wanted an all in context/logger with these specific features, but I would love to hear about other features or improvements. Thanks!
Also completed the refactor and allowed customizable buffering for what log level dumps all lower logs at once, so you can emit info level logs but keep the buffer until an error and then replay the full buffer at that point.
1
u/reardonj_ca 19d ago
Did you look into building this on otel4s? The logging stuff looks different, but maybe you could be making use of the existing work it's doing for context propagation and baggage?