Log system instead of printf and fprintf(stderr, ...)#321
Log system instead of printf and fprintf(stderr, ...)#321Purplesmaug96 wants to merge 57 commits into
Conversation
|
can i please use dup2 or something to redirect stdout/err to a file |
|
What use case is there? Maybe for other backends where stdout is less accessible like mobile or consoles it would make sense, but for the desktop backend? why? |
|
Oh wait, is it windows? its windows isnt it. |
|
mainly just want to be able to view it in my ide without "./butterscotch 2>&1 | tee out.log" |
|
What fucked up and evil IDE do you have that won't show you stdout?!??! |
|
Doesn't every IDE have an integrated terminal or at least launches a terminal along with the app? |
|
i use vscodium and just launch my stuff on konsole normally |
|
I used to use vscode it has an integrated terminal, why not just use that? |
|
too small, if i make it bigger it takes up the code space |
|
Can't you configure vscode to launch an external terminal? |
|
probably but i dont wanna it works fine as is |
|
Just use tee, setup an alias in your shell to make it easier to type. |
|
nah I'll just deal with there not being a log file or add a temporary write to file shim thing |
| #include <stdbool.h> | ||
| #include <stdarg.h> | ||
|
|
||
| #define LOG_MAX_FILES 16 |
There was a problem hiding this comment.
yeah forgot to remove it
|
Since you need to check if stdout is a tty for weather color should be enabled, and because color might not be desirable on some platforms, you should make color get handled in platformLog instead of in the dedicated log functions. |
|
Here's a better platformLog implementation actually void platformLog(const logType type, const char *format, va_list va) {
FILE *out = stderr;
switch (type) {
case LOG_TYPE_NORMAL:
out = stdout;
break;
case LOG_TYPE_WARNING:
fputs("\033[33mWarning:\033[0m ", out);
break;
case LOG_TYPE_ERROR:
fputs("\033[31mError:\033[0m ", out);
break;
}
vfprintf(out, format, va);
}This also properly resets the color which wasn't being done before. |
Only tested it on desktop/sdl3, seems to work fine there
Logs to ./butterscotch.log by default