Hi All,
I like the ability to filter down logs by scope/namespace a.l.a. logback and a while back I built an implementation of that concept for myself in Nim. I'm now building a new API server in Nim (using and loving mummy) and my little logging library that I threw together wasn't really production ready. I'm also trying to go all-in on structured logging in production. Over the long weekend I finally got around to refactoring my little library to be more production-ready and to support structured logging natively.
In addition to namespaces, namespaced_logging is intended to be a high-performance, thread-safe logging framework similar to std/logging with support for namespace-scoped logging similar to log4j or logback for Nim. It has four main motivating features:
it relies on the Nim GC and is intended to be fully GC-safe. There should be no need for manual memory management.
Currently it requires --threads:on and will not compile with --threads:off as it uses channels for thread-safe IO. I may add support for --threads:off but don't have any pressing need at the moment.
The README should be fairly comprehensive.
I'm interested in feedback. I've spent a fair amount of time thinking through the multi-threading behavior, reference semantics, etc., but would very much appreciate additional eyes. Let me know where I've screwed up.
I expect to keep the v2 contracts stable, but I will be working this into our production setup in the next few days/weeks and may have changes as I use it for real.
If this is useful, please feel free to use it. I haven't decided on a license yet, but will probably just default to MIT.
There's a ton of literature around the idea but not all of it is good. In my experience having some consistent JSON structure becomes useful when you push logs into something like Grafana Loki or something other log database.
By default this library logs the messages as text, similar to std/logging.