bspinner / amiberry-android

Android Amiga emulator based on Amiberry, the optimized Amiga emulator for the Raspberry Pi and other ARM boards
3 stars 0 forks source link

Provide proper logging to logcat #5

Open bspinner opened 4 years ago

bspinner commented 4 years ago

As of now, the write_log redirection to SDL_Log leads to crashes and will be removed soon (writing to logfile works now). Logcat output might be interesting in the future for proper crashlogs from users.

bspinner commented 4 years ago

Doing something like this could be a solution

#ifdef ANDROID
#include <android/log.h>
#define write_log(...) __android_log_print(ANDROID_LOG_INFO, "WRITELOG", __VA_ARGS__)
#else
extern void write_log (const TCHAR *,...);
#endif

but with above's code write_logfile setting isn't respected

midwan commented 4 years ago

The current version of write_log is as follows:

void write_log(const char* format, ...)
{
    if (write_logfile)
    {
        // Redirect logging to Android's logcat
#ifdef ANDROID
        va_list parms;
        va_start(parms, format);
        SDL_Log(format, parms);
        va_end(parms);
#else

        TCHAR buffer[WRITE_LOG_BUF_SIZE];

        va_list parms;
        va_start(parms, format);
        auto count = vsnprintf(buffer, WRITE_LOG_BUF_SIZE - 1, format, parms);
        if (debugfile)
        {
            fprintf(debugfile, "%s", buffer);
            fflush(debugfile);
        }
        va_end(parms);

#endif
    }
}

If you added your suggested block inside the existing ifdef ANDROID block, it would also respect the setting.