Skip to content

Log system instead of printf and fprintf(stderr, ...)#321

Open
Purplesmaug96 wants to merge 57 commits into
ButterscotchRunner:mainfrom
Purplesmaug96:log
Open

Log system instead of printf and fprintf(stderr, ...)#321
Purplesmaug96 wants to merge 57 commits into
ButterscotchRunner:mainfrom
Purplesmaug96:log

Conversation

@Purplesmaug96

Copy link
Copy Markdown
Contributor

Only tested it on desktop/sdl3, seems to work fine there
Logs to ./butterscotch.log by default

@Purplesmaug96

Copy link
Copy Markdown
Contributor Author

can i please use dup2 or something to redirect stdout/err to a file

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

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?

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Oh wait, is it windows? its windows isnt it.

@Purplesmaug96

Purplesmaug96 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

mainly just want to be able to view it in my ide without "./butterscotch 2>&1 | tee out.log"
Edit: no i use arch (btw) but if i ever am forced to use butterscotch on windows it would be useful, although you can get it to display a second terminal window for stdout

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

What fucked up and evil IDE do you have that won't show you stdout?!??!

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Doesn't every IDE have an integrated terminal or at least launches a terminal along with the app?

@Purplesmaug96

Purplesmaug96 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

i use vscodium and just launch my stuff on konsole normally

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

I used to use vscode it has an integrated terminal, why not just use that?

@Purplesmaug96

Purplesmaug96 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

too small, if i make it bigger it takes up the code space
not on a second monitor
i think its sandboxed so wont work with msvc via wine

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Can't you configure vscode to launch an external terminal?

@Purplesmaug96

Copy link
Copy Markdown
Contributor Author

probably but i dont wanna it works fine as is

@Un1q32

Un1q32 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Just use tee, setup an alias in your shell to make it easier to type. alias bscotch='./butterscotch 2>&1 | tee out.log'

@Purplesmaug96

Copy link
Copy Markdown
Contributor Author

nah I'll just deal with there not being a log file or add a temporary write to file shim thing

Comment thread src/log.h Outdated
#include <stdbool.h>
#include <stdarg.h>

#define LOG_MAX_FILES 16

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah forgot to remove it

@Un1q32

Un1q32 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

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.

@Un1q32

Un1q32 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants