Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Provide proper logging to logcat #5

Open
bspinner opened this issue Dec 21, 2019 · 2 comments
Open

Provide proper logging to logcat #5

bspinner opened this issue Dec 21, 2019 · 2 comments
Labels
meta Meta-issue about the project (solving these won't improve the app, but developers' lifes)
Milestone

Comments

@bspinner
Copy link
Owner

bspinner commented Dec 21, 2019

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 bspinner changed the title Logging crashes in custom.cpp Fix crashes in Logging in custom.cpp Dec 26, 2019
@bspinner bspinner added the bug Something isn't working label Dec 26, 2019
@bspinner bspinner changed the title Fix crashes in Logging in custom.cpp Provide proper logging to logcat Jan 2, 2020
@bspinner bspinner added meta Meta-issue about the project (solving these won't improve the app, but developers' lifes) and removed bug Something isn't working labels Jan 2, 2020
@bspinner bspinner added this to the alpha1 milestone Jan 3, 2020
@bspinner
Copy link
Owner Author

bspinner commented Jan 3, 2020

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
Copy link
Collaborator

midwan commented Jan 3, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
meta Meta-issue about the project (solving these won't improve the app, but developers' lifes)
Projects
None yet
Development

No branches or pull requests

2 participants