I’m trying to improve a weird logging library.
Here’s how it works :
- there are several logging levels, let’s just assume 2 (Normal and Verbose) for the sake of simplicity.
- when i call
log_normal <string>it writes the string in the normal log file.
- when I call
log_verbose <string>it writes the string in the verbose log file AND the normal log file.
So instead giving the verbosity level as a parameter, the logging library just writes in several files and then the user can chose which to open. (Consider that choice out of my reach)
However, building the strings is extremely long. So there’s a trick involving
lazy strings, and a flag that silences the logs. Therefore the strings are only built when it’s not on silent mode. When the logs are active, the program takes at least twice the time to run than in silent mode. It can go up to 5 times depending…
So I want to move to :
- using Fmt instead of stringifiers so that we are not building huge strings by concatenation but simply writing as we go
- using Lwt_fmt to have some non-blocking wirting for free.
The issue is, in the previous version, once the string is built, we can write it in several files. So there is a single call to the stringifiers.
In this version, I don’t see how I could call the pretty-printers a single time to write into several files using Lwt_fmt.fprintf. I could write into a string and then write it in several files but I would lose the interest…
If anyone has an idea, it would be great ! Thanks