kprintf with delayed string construction
Currently kprintf and friends take in a continuation function and a StringFormat and return a curried function that when applied builds the string.
It would be nice for logging frameworks to have an overload where the continuation does not build the string rather provides a delayed function to build the string.
That way I can do something like:
let public logWithFormat logLevel logFormat =
kprintf (fun stringBuilder -> if logLevel > currentLoggingLevel then sprintf "%s" (stringBuilder())) logFormat
Robin Munn commented
If this is implemented, I'd suggest a name incorporating "d" for "delay", e.g. one of the following naming schemes:
dprintf, dbprintf, dfprintf, dsprintf
dkprintf, dkbprintf, dkfprintf, dksprintf
kdprintf, kdbprintf, kdfprintf, kdsprintf
kprintfd, kbprintfd, kfprintfd, ksprintfd
Personally, I like the last scheme best, where the "d" is appended at the end of the "normal" kprintf names. That fits with the printf / printfn function naming, where the two functions do ALMOST the same thing with one minor change (whether a newline is appended or not). Since no kprintf-family functions have an "n" overload, there won't be any confusion over whether to put the "d" before or after the "n", and the parallels to printf / printfn are clear (the "d" functions work almost the same as the non-"d" functions, but delay calling the continuation).
A related stack overflow thread with the same issue: http://stackoverflow.com/questions/31442608/how-to-wrap-sprintf-conditionally-in-f