liblogging
liblogging copied to clipboard
Add more \xxx escapes to printf implementation
We currently support a too-small subset. But before we extend it, we should think if we really want to have control characters inside our log messages (or maybe make this a config option?).
I admit I am not even sure if it is a good idea to permit them...
I might support \ooo or \xhhh escapes, so that people who are using a non-ASCII character set can specify non-ASCII characters if required (not necessarily control characters).
Thanks for the suggestion! If you'd like to contribute that code, just send me a patch or pull request. If you have no time, I'll most probably do it some time later this week.
I'm a little unsure what exactly this issue is trying to address. Are you talking about the backslash-escape formatting in __stdlog_sigsafe_printf()? I don't understand why that is even present. If I specify something like:
stdlog(..., "This is a message with embedded newlines specified as hex: \x0a octal: \012 and symbol: \n");
The compiler translates those escapes; __stdlog_sigsafe_printf() will never see them, so there is no need to have "support" for them in that function. In fact, I would be very surprised if I wrote:
stdlog(..., "message with literal backslash-n \\n embedded");
and found that stdlog turned that into a log message like:
message with literal backslash-n
embedded
I think that is what the existing code does and that section should be removed.
Am I missing something?
IIRC the intent was to actually escape (LF) back to ('','n') so that control characters cannot render the log unreadable.