SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL3 Request: SDL_LogOutputRaw (fputs equivalent)

Open namandixit opened this issue 1 year ago • 0 comments

For custom log formatting, one can use SetLogOutputFunction. However, after creating the log string, there is still the question of actually outputting it. SDL currently has no function to simply send the data to the right stream (stdout, stderr, or OutputDebugString) without modifying it. This means the application has to rewrite the same logic all over again (check IsDebuggerPresent(), convert to UTF-16, etc.).

The closest alternative is to use SetLogPriorityPrefix to remove prefixes, and then get the function pointer to SDL_LogOutput through GetLogOutputFunction. But this function modifies the input by adding a newline at the end of the string. And this workflow is not very intuitive, to say the least.

What can be done is add a function SDL_LogOutputRaw (similar to SDL_LogOutput) that takes only a string as argument, and outputs it to the appropriate stream without any modification (besides unicode conversion).

void SDL_LogOutputRaw(const char *message)

The SDL_LogOutput function can simply be rewritten to use SDL_LogOutputRaw to prevent code duplication. This will also separate out the code responsible for formatting from code responsible for outputting.

namandixit avatar Aug 28 '24 01:08 namandixit