24 points · by linkdd · 2y ago · 42 comments
What you need:
- an asynchronous design where both the formatting and the writing to disk can happen on another thread.
- a lockfree buffer using pre-allocated memory. In particular every log record might be of different size.
- the ability to control where/when to drain that buffer, perform formatting and write data to disk (no good library should impose a threading model, needs to be able to cooperatively run with other tasks on one thread)
- an extensible and fast binary serialization/deserialization scheme -- easiest is to rely on simple copy construction as a default.
Most libraries focus on silly things like formatting and filtering which are all trivial problems.
I wanted to print structured data on stdout, without any fuss. All the other libraries that try to tackle the non trivial problems you mention, feel like a bazooka aiming at the ant that is my use case.
Not all formatting is amenable to being pushed to another thread without introducing undesirable concurrency concerns.
It's good enough for 100% of my use cases.
There's barely a point in supporting moduleso sfar unless you really enjoy pain.
If we don't try to use them, we cannot complain they don't get used, someone has to submit bug reports.
MSVC chokes on many standard-defined constructs: https://github.com/microsoft/STL/issues/1694
clang does not claim to be "mostly usable" at all - most papers are not implemented: https://clang.llvm.org/cxx_status.html#cxx20
And gcc will only start ot be usable with CMake when version 14 is released - that has not happened yet.
And, as I mentioned before, IDE support is either buggy (Visual Studio) or non-existing (any other IDE/OS). So you're off to writing in a text editor and hoping your compiler works to a somewhat usable degree. Yes, at some point people should start using modules, I agree, but to advise library maintainers to ship modularized code... the tooling just isn't there yet.
I mean, the GitHub issue is Microsoft trying to ship their standard library modularized, they employ some of the most capable folks on the planet and pay them big money to get that done, while metaphorically sitting next to the Microsoft compiler devs, and they barely, barely get it done (with bugs, as they themselves mention). This is too much for most other library maintainers.
We already moved beyond a state where nothing really worked, to at very least being able to write CLI stuff using import std and our own libraries, alongside module fragments.
I have a couple of hobby projects on Github using modules.
I haven't written any benchmark, but I assume this would be the bottleneck. I made this tool for a small CLI utility not concerned about performance.
I'd be happy to receive recommendations (and even PRs) though.
logger.log( logfmtxx::level::error, "internal server error", logfmtxx::field{"http.method", "GET"}, logfmtxx::field{"http.path", "/"}, logfmtxx::field{"http.status", 500} );
This is a very dated approach to structural logging.
Modern implementations are effortless: https://izumi.7mind.io/logstage/index.html
I guess the definition of "effortless" varies from people to people, I find this "no hard setup required" way to be effortless.
logger.log_error("internal server error", {{"http.method", "GET"}, {"http.path", "/"}, {"http.status", 500}} );Thank you for the feedback.
And of course, it eliminates a third-party code dependency in your other projects.
Making it for fun or DIY is also a reasonable answer.