(iOS) If the token HAVE_DEBUG_DIAGLOG is defined at build time all messages sent to stdout or stderr will appear in the Diagnostic Log.
This commit is contained in:
parent
bd2f308f46
commit
6affc4572e
|
@ -20,6 +20,7 @@
|
|||
static NSMutableArray* g_messages;
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#ifndef HAVE_DEBUG_DIAGLOG
|
||||
void ios_add_log_message(const char* format, ...)
|
||||
{
|
||||
pthread_mutex_lock(&g_lock);
|
||||
|
@ -36,6 +37,54 @@ void ios_add_log_message(const char* format, ...)
|
|||
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
#else
|
||||
static FILE* old_stdout;
|
||||
static FILE* old_stderr;
|
||||
static FILE* log_stream;
|
||||
|
||||
static int stdout_write(void* mem_buffer, const char* data, int len)
|
||||
{
|
||||
pthread_mutex_lock(&g_lock);
|
||||
|
||||
g_messages = g_messages ? g_messages : [NSMutableArray array];
|
||||
|
||||
char buffer[len + 10];
|
||||
strncpy(buffer, data, len);
|
||||
buffer[len] = 0;
|
||||
|
||||
[g_messages addObject:[NSString stringWithFormat:@"%s", buffer]];
|
||||
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void ios_log_init()
|
||||
{
|
||||
if (!log_stream)
|
||||
{
|
||||
old_stdout = stdout;
|
||||
old_stderr = stderr;
|
||||
|
||||
log_stream = fwopen(0, stdout_write);
|
||||
setvbuf(log_stream, 0, _IOLBF, 0);
|
||||
|
||||
stdout = log_stream;
|
||||
stderr = log_stream;
|
||||
}
|
||||
}
|
||||
|
||||
void ios_log_quit()
|
||||
{
|
||||
if (log_stream)
|
||||
{
|
||||
stdout = old_stdout;
|
||||
stderr = old_stderr;
|
||||
fclose(log_stream);
|
||||
log_stream = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@implementation RALogView
|
||||
|
||||
|
|
|
@ -231,6 +231,10 @@ static void event_reload_config(void* userdata)
|
|||
// UIApplicationDelegate
|
||||
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
||||
{
|
||||
#ifdef HAVE_DEBUG_DIAGLOG
|
||||
ios_log_init();
|
||||
#endif
|
||||
|
||||
self.system_directory = [NSString stringWithFormat:@"%@/.RetroArch", kDOCSFOLDER];
|
||||
self.systemConfigPath = [NSString stringWithFormat:@"%@/.RetroArch/frontend.cfg", kDOCSFOLDER];
|
||||
mkdir([self.system_directory UTF8String], 0755);
|
||||
|
|
|
@ -30,6 +30,13 @@ void ios_set_game_view_sync(unsigned interval);
|
|||
void ios_get_game_view_size(unsigned *width, unsigned *height);
|
||||
void ios_bind_game_view_fbo();
|
||||
|
||||
// Thread safe
|
||||
#ifndef HAVE_DEBUG_DIAGLOG
|
||||
void ios_add_log_message(const char* format, ...);
|
||||
#else
|
||||
void ios_log_init();
|
||||
void ios_log_quit();
|
||||
// Thread safe
|
||||
#define ios_add_log_message(...) do { printf(__VA_ARGS__); printf("\n"); } while(0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue