Browse Source

Improve logging performance and make log priorities thread-safe

Fixes https://github.com/libsdl-org/SDL/issues/9679
Sam Lantinga 7 months ago
parent
commit
dc639956ba
69 changed files with 283 additions and 343 deletions
  1. 36 4
      include/SDL3/SDL_log.h
  2. 4 4
      src/SDL.c
  3. 242 131
      src/SDL_log.c
  4. 0 3
      test/checkkeys.c
  5. 0 3
      test/loopwave.c
  6. 0 3
      test/testatomic.c
  7. 0 3
      test/testaudiohotplug.c
  8. 0 3
      test/testaudioinfo.c
  9. 0 3
      test/testaudiorecording.c
  10. 0 3
      test/testaudiostreamdynamicresample.c
  11. 0 3
      test/testcamera.c
  12. 0 3
      test/testcontroller.c
  13. 0 3
      test/testcustomcursor.c
  14. 0 3
      test/testdialog.c
  15. 0 3
      test/testdisplayinfo.c
  16. 0 3
      test/testdraw.c
  17. 0 3
      test/testdrawchessboard.c
  18. 0 3
      test/testdropfile.c
  19. 0 3
      test/testerror.c
  20. 0 3
      test/testfile.c
  21. 0 3
      test/testfilesystem.c
  22. 0 3
      test/testgeometry.c
  23. 0 3
      test/testgl.c
  24. 0 3
      test/testgles.c
  25. 0 3
      test/testgpu_simple_clear.c
  26. 0 2
      test/testhaptic.c
  27. 0 3
      test/testhittesting.c
  28. 0 6
      test/testhotplug.c
  29. 0 3
      test/testiconv.c
  30. 0 3
      test/testime.c
  31. 0 3
      test/testintersections.c
  32. 0 3
      test/testkeys.c
  33. 0 3
      test/testloadso.c
  34. 0 3
      test/testlocale.c
  35. 0 2
      test/testlock.c
  36. 0 3
      test/testmanymouse.c
  37. 0 3
      test/testmessage.c
  38. 0 3
      test/testmodal.c
  39. 0 3
      test/testmouse.c
  40. 0 3
      test/testmultiaudio.c
  41. 0 3
      test/testnative.c
  42. 0 3
      test/testoffscreen.c
  43. 0 3
      test/testpen.c
  44. 0 3
      test/testplatform.c
  45. 0 3
      test/testpopup.c
  46. 0 3
      test/testpower.c
  47. 0 3
      test/testprocess.c
  48. 0 3
      test/testrelative.c
  49. 0 3
      test/testrendercopyex.c
  50. 0 3
      test/testrendertarget.c
  51. 0 3
      test/testresample.c
  52. 0 3
      test/testrumble.c
  53. 0 2
      test/testrwlock.c
  54. 0 3
      test/testscale.c
  55. 0 3
      test/testsem.c
  56. 0 3
      test/testsensor.c
  57. 0 3
      test/testshader.c
  58. 0 3
      test/testspriteminimal.c
  59. 0 3
      test/testspritesurface.c
  60. 0 3
      test/teststreaming.c
  61. 0 3
      test/testsurround.c
  62. 0 3
      test/testthread.c
  63. 0 3
      test/testtime.c
  64. 0 3
      test/testtimer.c
  65. 0 3
      test/testver.c
  66. 0 3
      test/testvulkan.c
  67. 1 3
      test/testwm.c
  68. 0 3
      test/testyuv.c
  69. 0 9
      test/torturethread.c

+ 36 - 4
include/SDL3/SDL_log.h

@@ -120,7 +120,8 @@ typedef enum SDL_LogCategory
  */
 typedef enum SDL_LogPriority
 {
-    SDL_LOG_PRIORITY_VERBOSE = 1,
+    SDL_LOG_PRIORITY_INVALID,
+    SDL_LOG_PRIORITY_VERBOSE,
     SDL_LOG_PRIORITY_DEBUG,
     SDL_LOG_PRIORITY_INFO,
     SDL_LOG_PRIORITY_WARN,
@@ -135,6 +136,8 @@ typedef enum SDL_LogPriority
  *
  * \param priority the SDL_LogPriority to assign.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_ResetLogPriorities
@@ -148,14 +151,15 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriorities(SDL_LogPriority priority);
  * \param category the category to assign a priority to.
  * \param priority the SDL_LogPriority to assign.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_GetLogPriority
  * \sa SDL_ResetLogPriorities
  * \sa SDL_SetLogPriorities
  */
-extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category,
-                                                SDL_LogPriority priority);
+extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category, SDL_LogPriority priority);
 
 /**
  * Get the priority of a particular log category.
@@ -163,6 +167,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category,
  * \param category the category to query.
  * \returns the SDL_LogPriority for the requested category.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_SetLogPriority
@@ -174,6 +180,8 @@ extern SDL_DECLSPEC SDL_LogPriority SDLCALL SDL_GetLogPriority(int category);
  *
  * This is called by SDL_Quit().
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_SetLogPriorities
@@ -194,6 +202,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);
  * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
  *          for more information.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_SetLogPriorities
@@ -208,6 +218,8 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority pr
  * \param ... additional parameters matching % tokens in the `fmt` string, if
  *            any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_LogCritical
@@ -229,6 +241,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fm
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -250,6 +264,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -271,6 +287,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_ST
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -292,6 +310,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STR
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -313,6 +333,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STR
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -334,6 +356,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_ST
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -356,6 +380,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT
  * \param ... additional parameters matching % tokens in the **fmt** string,
  *            if any.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -379,6 +405,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,
  * \param fmt a printf() style message format string.
  * \param ap a variable argument list.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_Log
@@ -397,7 +425,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,
 /**
  * The prototype for the log output callback function.
  *
- * This function is called by SDL when there is new text to be logged.
+ * This function is called by SDL when there is new text to be logged. A mutex is held so that this function is never called by more than one thread at once.
  *
  * \param userdata what was passed as `userdata` to
  *                 SDL_SetLogOutputFunction().
@@ -417,6 +445,8 @@ typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_
  * \param userdata a pointer filled in with the pointer that is passed to
  *                 `callback`.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_SetLogOutputFunction
@@ -429,6 +459,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction
  * \param callback an SDL_LogOutputFunction to call instead of the default.
  * \param userdata a pointer that is passed to `callback`.
  *
+ * \threadsafety It is safe to call this function from any thread.
+ *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_GetLogOutputFunction

+ 4 - 4
src/SDL.c

@@ -252,21 +252,21 @@ void SDL_InitMainThread(void)
 {
     SDL_InitTLSData();
     SDL_InitEnvironment();
+    SDL_InitProperties();
+    SDL_InitHints();
     SDL_InitTicks();
     SDL_InitFilesystem();
     SDL_InitLog();
-    SDL_InitProperties();
     SDL_GetGlobalProperties();
-    SDL_InitHints();
 }
 
 static void SDL_QuitMainThread(void)
 {
-    SDL_QuitHints();
-    SDL_QuitProperties();
     SDL_QuitLog();
     SDL_QuitFilesystem();
     SDL_QuitTicks();
+    SDL_QuitHints();
+    SDL_QuitProperties();
     SDL_QuitEnvironment();
     SDL_QuitTLSData();
 }

+ 242 - 131
src/SDL_log.c

@@ -54,14 +54,18 @@ typedef struct SDL_LogLevel
 // The default log output function
 static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message);
 
-static void SDL_ResetLogPrefixes(void);
-
-static SDL_LogLevel *SDL_loglevels;
-static bool SDL_forced_priority = false;
-static SDL_LogPriority SDL_forced_priority_level;
-static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
-static void *SDL_log_userdata = NULL;
-static SDL_Mutex *log_function_mutex = NULL;
+static void CleanupLogPriorities(void);
+static void CleanupLogPrefixes(void);
+
+static SDL_AtomicInt SDL_log_initializing;
+static SDL_AtomicInt SDL_log_initialized;
+static SDL_Mutex *SDL_log_lock;
+static SDL_Mutex *SDL_log_function_lock;
+static SDL_LogLevel *SDL_loglevels SDL_GUARDED_BY(SDL_log_lock);
+static SDL_LogPriority SDL_log_priorities[SDL_LOG_CATEGORY_CUSTOM] SDL_GUARDED_BY(SDL_log_lock);
+static SDL_LogPriority SDL_log_default_priority SDL_GUARDED_BY(SDL_log_lock);
+static SDL_LogOutputFunction SDL_log_function SDL_GUARDED_BY(SDL_log_function_lock) = SDL_LogOutput;
+static void *SDL_log_userdata SDL_GUARDED_BY(SDL_log_function_lock) = NULL;
 
 #ifdef HAVE_GCC_DIAGNOSTIC_PRAGMA
 #pragma GCC diagnostic push
@@ -80,7 +84,8 @@ static const char * const SDL_priority_names[] = {
 };
 SDL_COMPILE_TIME_ASSERT(priority_names, SDL_arraysize(SDL_priority_names) == SDL_LOG_PRIORITY_COUNT);
 
-static const char *SDL_priority_prefixes[SDL_LOG_PRIORITY_COUNT];
+// This is guarded by SDL_log_function_lock because it's the logging function that calls GetLogPriorityPrefix()
+static char *SDL_priority_prefixes[SDL_LOG_PRIORITY_COUNT] SDL_GUARDED_BY(SDL_log_function_lock);
 
 // If this list changes, update the documentation for SDL_HINT_LOGGING
 static const char * const SDL_category_names[] = {
@@ -113,59 +118,149 @@ static int SDL_android_priority[SDL_LOG_PRIORITY_COUNT] = {
 };
 #endif // SDL_PLATFORM_ANDROID
 
+static void SDLCALL SDL_LoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+    SDL_ResetLogPriorities();
+}
+
 void SDL_InitLog(void)
 {
-    if (!log_function_mutex) {
-        // if this fails we'll try to continue without it.
-        log_function_mutex = SDL_CreateMutex();
+    if (SDL_AtomicGet(&SDL_log_initialized)) {
+        return;
+    }
+
+    // Do a little tap dance to make sure only one thread initializes logging
+    if (!SDL_AtomicCompareAndSwap(&SDL_log_initializing, false, true)) {
+        // Wait for the other thread to complete initialization
+        while (!SDL_AtomicGet(&SDL_log_initialized)) {
+            SDL_Delay(1);
+        }
+        return;
     }
+
+    // If these fail we'll continue without them.
+    SDL_log_lock = SDL_CreateMutex();
+    SDL_log_function_lock = SDL_CreateMutex();
+
+    SDL_AddHintCallback(SDL_HINT_LOGGING, SDL_LoggingChanged, NULL);
+
+    SDL_AtomicSet(&SDL_log_initializing, false);
+
+    SDL_AtomicSet(&SDL_log_initialized, true);
 }
 
 void SDL_QuitLog(void)
 {
-    SDL_ResetLogPriorities();
-    SDL_ResetLogPrefixes();
+    SDL_RemoveHintCallback(SDL_HINT_LOGGING, SDL_LoggingChanged, NULL);
+
+    CleanupLogPriorities();
+    CleanupLogPrefixes();
 
-    if (log_function_mutex) {
-        SDL_DestroyMutex(log_function_mutex);
-        log_function_mutex = NULL;
+    if (SDL_log_lock) {
+        SDL_DestroyMutex(SDL_log_lock);
+        SDL_log_lock = NULL;
     }
+    if (SDL_log_function_lock) {
+        SDL_DestroyMutex(SDL_log_function_lock);
+        SDL_log_function_lock = NULL;
+    }
+    SDL_AtomicSet(&SDL_log_initialized, false);
 }
 
-void SDL_SetLogPriorities(SDL_LogPriority priority)
+static void SDL_CheckInitLog()
 {
-    SDL_LogLevel *entry;
+    if (!SDL_AtomicGet(&SDL_log_initialized) &&
+        !SDL_AtomicGet(&SDL_log_initializing)) {
+        SDL_InitLog();
+    }
+}
 
-    for (entry = SDL_loglevels; entry; entry = entry->next) {
-        entry->priority = priority;
+static void CleanupLogPriorities(void)
+{
+    while (SDL_loglevels) {
+        SDL_LogLevel *entry = SDL_loglevels;
+        SDL_loglevels = entry->next;
+        SDL_free(entry);
     }
+}
+
+void SDL_SetLogPriorities(SDL_LogPriority priority)
+{
+    SDL_CheckInitLog();
+
+    SDL_LockMutex(SDL_log_lock);
+    {
+        CleanupLogPriorities();
 
-    SDL_forced_priority = true;
-    SDL_forced_priority_level = priority;
+        SDL_log_default_priority = priority;
+        for (int i = 0; i < SDL_arraysize(SDL_log_priorities); ++i) {
+            SDL_log_priorities[i] = priority;
+        }
+    }
+    SDL_UnlockMutex(SDL_log_lock);
 }
 
 void SDL_SetLogPriority(int category, SDL_LogPriority priority)
 {
     SDL_LogLevel *entry;
 
-    for (entry = SDL_loglevels; entry; entry = entry->next) {
-        if (entry->category == category) {
-            entry->priority = priority;
-            return;
+    SDL_CheckInitLog();
+
+    SDL_LockMutex(SDL_log_lock);
+    {
+        if (category >= 0 && category < SDL_arraysize(SDL_log_priorities)) {
+            SDL_log_priorities[category] = priority;
+        } else {
+            for (entry = SDL_loglevels; entry; entry = entry->next) {
+                if (entry->category == category) {
+                    entry->priority = priority;
+                    break;
+                }
+            }
+
+            if (!entry) {
+                entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
+                if (entry) {
+                    entry->category = category;
+                    entry->priority = priority;
+                    entry->next = SDL_loglevels;
+                    SDL_loglevels = entry;
+                }
+            }
         }
     }
+    SDL_UnlockMutex(SDL_log_lock);
+}
 
-    // Create a new entry
-    entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
-    if (entry) {
-        entry->category = category;
-        entry->priority = priority;
-        entry->next = SDL_loglevels;
-        SDL_loglevels = entry;
+SDL_LogPriority SDL_GetLogPriority(int category)
+{
+    SDL_LogLevel *entry;
+    SDL_LogPriority priority = SDL_LOG_PRIORITY_INVALID;
+
+    SDL_CheckInitLog();
+
+    SDL_LockMutex(SDL_log_lock);
+    {
+        if (category >= 0 && category < SDL_arraysize(SDL_log_priorities)) {
+            priority = SDL_log_priorities[category];
+        } else {
+            for (entry = SDL_loglevels; entry; entry = entry->next) {
+                if (entry->category == category) {
+                    priority = entry->priority;
+                    break;
+                }
+            }
+            if (priority == SDL_LOG_PRIORITY_INVALID) {
+                priority = SDL_log_default_priority;
+            }
+        }
     }
+    SDL_UnlockMutex(SDL_log_lock);
+
+    return priority;
 }
 
-static bool SDL_ParseLogCategory(const char *string, size_t length, int *category)
+static bool ParseLogCategory(const char *string, size_t length, int *category)
 {
     int i;
 
@@ -188,7 +283,7 @@ static bool SDL_ParseLogCategory(const char *string, size_t length, int *categor
     return false;
 }
 
-static bool SDL_ParseLogPriority(const char *string, size_t length, SDL_LogPriority *priority)
+static bool ParseLogPriority(const char *string, size_t length, SDL_LogPriority *priority)
 {
     int i;
 
@@ -220,13 +315,17 @@ static bool SDL_ParseLogPriority(const char *string, size_t length, SDL_LogPrior
     return false;
 }
 
-static bool SDL_ParseLogCategoryPriority(const char *hint, int category, SDL_LogPriority *priority)
+static void ParseLogPriorities(const char *hint)
 {
     const char *name, *next;
-    int current_category;
+    int category = DEFAULT_CATEGORY;
+    SDL_LogPriority priority = SDL_LOG_PRIORITY_COUNT;
 
-    if (category == DEFAULT_CATEGORY && SDL_strchr(hint, '=') == NULL) {
-        return SDL_ParseLogPriority(hint, SDL_strlen(hint), priority);
+    if (SDL_strchr(hint, '=') == NULL) {
+        if (ParseLogPriority(hint, SDL_strlen(hint), &priority)) {
+            SDL_SetLogPriorities(priority);
+        }
+        return;
     }
 
     for (name = hint; name; name = next) {
@@ -239,85 +338,86 @@ static bool SDL_ParseLogCategoryPriority(const char *hint, int category, SDL_Log
             ++next;
         }
 
-        if (SDL_ParseLogCategory(name, (sep - name), &current_category)) {
-            if (current_category == category) {
-                const char *value = sep + 1;
-                size_t len;
-                if (next) {
-                    len = (next - value - 1);
+        if (ParseLogCategory(name, (sep - name), &category)) {
+            const char *value = sep + 1;
+            size_t len;
+            if (next) {
+                len = (next - value - 1);
+            } else {
+                len = SDL_strlen(value);
+            }
+            if (ParseLogPriority(value, len, &priority)) {
+                if (category == DEFAULT_CATEGORY) {
+                    for (int i = 0; i < SDL_arraysize(SDL_log_priorities); ++i) {
+                        if (SDL_log_priorities[i] == SDL_LOG_PRIORITY_INVALID) {
+                            SDL_log_priorities[i] = priority;
+                        }
+                    }
+                    SDL_log_default_priority = priority;
                 } else {
-                    len = SDL_strlen(value);
+                    SDL_SetLogPriority(category, priority);
                 }
-                return SDL_ParseLogPriority(value, len, priority);
             }
         }
     }
-    return false;
 }
 
-static SDL_LogPriority SDL_GetDefaultLogPriority(int category)
+void SDL_ResetLogPriorities(void)
 {
-    const char *hint = SDL_GetHint(SDL_HINT_LOGGING);
-    if (hint) {
-        SDL_LogPriority priority;
-
-        if (SDL_ParseLogCategoryPriority(hint, category, &priority)) {
-            return priority;
-        }
-        if (SDL_ParseLogCategoryPriority(hint, DEFAULT_CATEGORY, &priority)) {
-            return priority;
-        }
-    }
+    SDL_CheckInitLog();
 
-    switch (category) {
-    case SDL_LOG_CATEGORY_APPLICATION:
-        return SDL_LOG_PRIORITY_INFO;
-    case SDL_LOG_CATEGORY_ASSERT:
-        return SDL_LOG_PRIORITY_WARN;
-    case SDL_LOG_CATEGORY_TEST:
-        return SDL_LOG_PRIORITY_VERBOSE;
-    default:
-        return SDL_LOG_PRIORITY_ERROR;
-    }
-}
-
-SDL_LogPriority SDL_GetLogPriority(int category)
-{
-    SDL_LogLevel *entry;
+    SDL_LockMutex(SDL_log_lock);
+    {
+        CleanupLogPriorities();
 
-    for (entry = SDL_loglevels; entry; entry = entry->next) {
-        if (entry->category == category) {
-            return entry->priority;
+        SDL_log_default_priority = SDL_LOG_PRIORITY_INVALID;
+        for (int i = 0; i < SDL_arraysize(SDL_log_priorities); ++i) {
+            SDL_log_priorities[i] = SDL_LOG_PRIORITY_INVALID;
         }
-    }
 
-    if (SDL_forced_priority) {
-        return SDL_forced_priority_level;
-    }
-
-    return SDL_GetDefaultLogPriority(category);
-}
+        const char *hint = SDL_GetHint(SDL_HINT_LOGGING);
+        if (hint) {
+            ParseLogPriorities(hint);
+        }
 
-void SDL_ResetLogPriorities(void)
-{
-    SDL_LogLevel *entry;
+        if (SDL_log_default_priority == SDL_LOG_PRIORITY_INVALID) {
+            SDL_log_default_priority = SDL_LOG_PRIORITY_ERROR;
+        }
+        for (int i = 0; i < SDL_arraysize(SDL_log_priorities); ++i) {
+            if (SDL_log_priorities[i] != SDL_LOG_PRIORITY_INVALID) {
+                continue;
+            }
 
-    while (SDL_loglevels) {
-        entry = SDL_loglevels;
-        SDL_loglevels = entry->next;
-        SDL_free(entry);
+            switch (i) {
+            case SDL_LOG_CATEGORY_APPLICATION:
+                SDL_log_priorities[i] = SDL_LOG_PRIORITY_INFO;
+                break;
+            case SDL_LOG_CATEGORY_ASSERT:
+                SDL_log_priorities[i] = SDL_LOG_PRIORITY_WARN;
+                break;
+            case SDL_LOG_CATEGORY_TEST:
+                SDL_log_priorities[i] = SDL_LOG_PRIORITY_VERBOSE;
+                break;
+            default:
+                SDL_log_priorities[i] = SDL_LOG_PRIORITY_ERROR;
+                break;
+            }
+        }
     }
-    SDL_forced_priority = false;
+    SDL_UnlockMutex(SDL_log_lock);
 }
 
-static void SDL_ResetLogPrefixes(void)
+static void CleanupLogPrefixes(void)
 {
     for (int i = 0; i < SDL_arraysize(SDL_priority_prefixes); ++i) {
-        SDL_priority_prefixes[i] = NULL;
+        if (SDL_priority_prefixes[i]) {
+            SDL_free(SDL_priority_prefixes[i]);
+            SDL_priority_prefixes[i] = NULL;
+        }
     }
 }
 
-static const char *SDL_GetLogPriorityPrefix(SDL_LogPriority priority)
+static const char *GetLogPriorityPrefix(SDL_LogPriority priority)
 {
     if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_LOG_PRIORITY_COUNT) {
         return "";
@@ -341,19 +441,30 @@ static const char *SDL_GetLogPriorityPrefix(SDL_LogPriority priority)
 
 SDL_bool SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix)
 {
-    if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_LOG_PRIORITY_COUNT) {
+    char *prefix_copy;
+
+    if (priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
         return SDL_InvalidParamError("priority");
     }
 
-    if (!prefix) {
-        prefix = "";
+    if (!prefix || !*prefix) {
+        prefix_copy = SDL_strdup("");
     } else {
-        prefix = SDL_GetPersistentString(prefix);
-        if (!prefix) {
-            return false;
+        prefix_copy = SDL_strdup(prefix);
+    }
+    if (!prefix_copy) {
+        return false;
+    }
+
+    SDL_LockMutex(SDL_log_function_lock);
+    {
+        if (SDL_priority_prefixes[priority]) {
+            SDL_free(SDL_priority_prefixes[priority]);
         }
+        SDL_priority_prefixes[priority] = prefix_copy;
     }
-    SDL_priority_prefixes[priority] = prefix;
+    SDL_UnlockMutex(SDL_log_function_lock);
+
     return true;
 }
 
@@ -455,21 +566,11 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S
         return;
     }
 
-    // Make sure we don't exceed array bounds
-    if ((int)priority < 0 || priority >= SDL_LOG_PRIORITY_COUNT) {
-        return;
-    }
-
     // See if we want to do anything with this message
     if (priority < SDL_GetLogPriority(category)) {
         return;
     }
 
-    if (!log_function_mutex) {
-        // this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first!
-        log_function_mutex = SDL_CreateMutex();
-    }
-
     // Render into stack buffer
     va_copy(aq, ap);
     len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq);
@@ -501,9 +602,11 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S
         }
     }
 
-    SDL_LockMutex(log_function_mutex);
-    SDL_log_function(SDL_log_userdata, category, priority, message);
-    SDL_UnlockMutex(log_function_mutex);
+    SDL_LockMutex(SDL_log_function_lock);
+    {
+        SDL_log_function(SDL_log_userdata, category, priority, message);
+    }
+    SDL_UnlockMutex(SDL_log_function_lock);
 
     // Free only if dynamically allocated
     if (message != stack_buf) {
@@ -575,9 +678,9 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
             }
         }
 #endif // !defined(SDL_PLATFORM_GDK)
-        length = SDL_strlen(SDL_GetLogPriorityPrefix(priority)) + SDL_strlen(message) + 1 + 1 + 1;
+        length = SDL_strlen(GetLogPriorityPrefix(priority)) + SDL_strlen(message) + 1 + 1 + 1;
         output = SDL_small_alloc(char, length, &isstack);
-        (void)SDL_snprintf(output, length, "%s%s\r\n", SDL_GetLogPriorityPrefix(priority), message);
+        (void)SDL_snprintf(output, length, "%s%s\r\n", GetLogPriorityPrefix(priority), message);
         tstr = WIN_UTF8ToString(output);
 
         // Output to debugger
@@ -615,7 +718,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
      */
     extern void SDL_NSLog(const char *prefix, const char *text);
     {
-        SDL_NSLog(SDL_GetLogPriorityPrefix(priority), message);
+        SDL_NSLog(GetLogPriorityPrefix(priority), message);
         return;
     }
 #elif defined(SDL_PLATFORM_PSP) || defined(SDL_PLATFORM_PS2)
@@ -623,7 +726,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
         FILE *pFile;
         pFile = fopen("SDL_Log.txt", "a");
         if (pFile) {
-            (void)fprintf(pFile, "%s%s\n", SDL_GetLogPriorityPrefix(priority), message);
+            (void)fprintf(pFile, "%s%s\n", GetLogPriorityPrefix(priority), message);
             (void)fclose(pFile);
         }
     }
@@ -632,7 +735,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
         FILE *pFile;
         pFile = fopen("ux0:/data/SDL_Log.txt", "a");
         if (pFile) {
-            (void)fprintf(pFile, "%s%s\n", SDL_GetLogPriorityPrefix(priority), message);
+            (void)fprintf(pFile, "%s%s\n", GetLogPriorityPrefix(priority), message);
             (void)fclose(pFile);
         }
     }
@@ -641,7 +744,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
         FILE *pFile;
         pFile = fopen("sdmc:/3ds/SDL_Log.txt", "a");
         if (pFile) {
-            (void)fprintf(pFile, "%s%s\n", SDL_GetLogPriorityPrefix(priority), message);
+            (void)fprintf(pFile, "%s%s\n", GetLogPriorityPrefix(priority), message);
             (void)fclose(pFile);
         }
     }
@@ -649,22 +752,30 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
 #if defined(HAVE_STDIO_H) && \
     !(defined(SDL_PLATFORM_APPLE) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT))) && \
     !(defined(SDL_PLATFORM_WIN32))
-    (void)fprintf(stderr, "%s%s\n", SDL_GetLogPriorityPrefix(priority), message);
+    (void)fprintf(stderr, "%s%s\n", GetLogPriorityPrefix(priority), message);
 #endif
 }
 
 void SDL_GetLogOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
 {
-    if (callback) {
-        *callback = SDL_log_function;
-    }
-    if (userdata) {
-        *userdata = SDL_log_userdata;
+    SDL_LockMutex(SDL_log_function_lock);
+    {
+        if (callback) {
+            *callback = SDL_log_function;
+        }
+        if (userdata) {
+            *userdata = SDL_log_userdata;
+        }
     }
+    SDL_UnlockMutex(SDL_log_function_lock);
 }
 
 void SDL_SetLogOutputFunction(SDL_LogOutputFunction callback, void *userdata)
 {
-    SDL_log_function = callback;
-    SDL_log_userdata = userdata;
+    SDL_LockMutex(SDL_log_function_lock);
+    {
+        SDL_log_function = callback;
+        SDL_log_userdata = userdata;
+    }
+    SDL_UnlockMutex(SDL_log_function_lock);
 }

+ 0 - 3
test/checkkeys.c

@@ -453,9 +453,6 @@ int main(int argc, char *argv[])
     }
     state->window_title = "CheckKeys Test";
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/loopwave.c

@@ -56,9 +56,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
         return SDL_APP_SUCCESS;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testatomic.c

@@ -712,9 +712,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testaudiohotplug.c

@@ -122,9 +122,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testaudioinfo.c

@@ -63,9 +63,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testaudiorecording.c

@@ -40,9 +40,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv)
         return SDL_APP_SUCCESS;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testaudiostreamdynamicresample.c

@@ -359,9 +359,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testcamera.c

@@ -59,9 +59,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
         return SDL_APP_FAILURE;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testcontroller.c

@@ -2005,9 +2005,6 @@ int main(int argc, char *argv[])
     SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
     SDL_SetHint(SDL_HINT_JOYSTICK_LINUX_DEADZONES, "1");
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Enable input debug logging */
     SDL_SetLogPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_DEBUG);
 

+ 0 - 3
test/testcustomcursor.c

@@ -382,9 +382,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testdialog.c

@@ -62,9 +62,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testdisplayinfo.c

@@ -45,9 +45,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testdraw.c

@@ -226,9 +226,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testdrawchessboard.c

@@ -111,9 +111,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testdropfile.c

@@ -34,9 +34,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
         return SDL_APP_FAILURE;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testerror.c

@@ -58,9 +58,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testfile.c

@@ -76,9 +76,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testfilesystem.c

@@ -70,9 +70,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testgeometry.c

@@ -194,9 +194,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testgl.c

@@ -231,9 +231,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testgles.c

@@ -115,9 +115,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testgpu_simple_clear.c

@@ -34,9 +34,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
         return SDL_APP_FAILURE;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     state->skip_renderer = 1;
 
     if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {

+ 0 - 2
test/testhaptic.c

@@ -49,8 +49,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testhittesting.c

@@ -86,9 +86,6 @@ int main(int argc, char **argv)
 
     state->window_flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE;
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 6
test/testhotplug.c

@@ -38,9 +38,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;
@@ -65,9 +62,6 @@ int main(int argc, char *argv[])
         init_subsystems |= SDL_INIT_HAPTIC;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
 
     /* Initialize SDL (Note: video is required to start event loop) */

+ 0 - 3
test/testiconv.c

@@ -88,9 +88,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testime.c

@@ -1039,9 +1039,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testintersections.c

@@ -295,9 +295,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testkeys.c

@@ -29,9 +29,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testloadso.c

@@ -45,9 +45,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testlocale.c

@@ -45,9 +45,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 2
test/testlock.c

@@ -120,8 +120,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testmanymouse.c

@@ -499,9 +499,6 @@ int main(int argc, char *argv[])
 {
     int i;
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Log all events, including mouse motion */
     SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
 

+ 0 - 3
test/testmessage.c

@@ -93,9 +93,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testmodal.c

@@ -31,9 +31,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testmouse.c

@@ -288,9 +288,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testmultiaudio.c

@@ -147,9 +147,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testnative.c

@@ -117,9 +117,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testoffscreen.c

@@ -100,9 +100,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testpen.c

@@ -46,9 +46,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
         return SDL_APP_FAILURE;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed = SDLTest_CommonArg(state, i);

+ 0 - 3
test/testplatform.c

@@ -451,9 +451,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testpopup.c

@@ -248,9 +248,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testpower.c

@@ -69,9 +69,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testprocess.c

@@ -567,9 +567,6 @@ int main(int argc, char *argv[])
 
     runner = SDLTest_CreateTestSuiteRunner(state, testSuites);
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testrelative.c

@@ -138,9 +138,6 @@ static void loop(void)
 
 int main(int argc, char *argv[])
 {
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Initialize test framework */
     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
     if (!state) {

+ 0 - 3
test/testrendercopyex.c

@@ -124,9 +124,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
         SDLTest_CommonQuit(state);
         return 1;

+ 0 - 3
test/testrendertarget.c

@@ -224,9 +224,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     for (i = 1; i < argc;) {
         int consumed;
 

+ 0 - 3
test/testresample.c

@@ -45,9 +45,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     SDL_zero(cvtspec);
 
     /* Parse commandline */

+ 0 - 3
test/testrumble.c

@@ -48,9 +48,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     name = NULL;
     index = -1;
 

+ 0 - 2
test/testrwlock.c

@@ -73,8 +73,6 @@ int main(int argc, char *argv[])
 
     SDL_AtomicSet(&doterminate, 0);
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testscale.c

@@ -111,9 +111,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testsem.c

@@ -266,9 +266,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testsensor.c

@@ -68,9 +68,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         SDL_Quit();
         SDLTest_CommonDestroyState(state);

+ 0 - 3
test/testshader.c

@@ -458,9 +458,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testspriteminimal.c

@@ -111,9 +111,6 @@ int main(int argc, char *argv[])
     int return_code = -1;
     int i;
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (argc > 1) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "USAGE: %s\n", argv[0]);
         return_code = 1;

+ 0 - 3
test/testspritesurface.c

@@ -105,9 +105,6 @@ int main(int argc, char *argv[])
     int return_code = -1;
     int i;
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (argc > 1) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "USAGE: %s\n", argv[0]);
         return_code = 1;

+ 0 - 3
test/teststreaming.c

@@ -145,9 +145,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         SDL_Quit();
         SDLTest_CommonDestroyState(state);

+ 0 - 3
test/testsurround.c

@@ -157,9 +157,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         SDLTest_CommonQuit(state);
         return 1;

+ 0 - 3
test/testthread.c

@@ -98,9 +98,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testtime.c

@@ -154,9 +154,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         return 1;

+ 0 - 3
test/testtimer.c

@@ -89,9 +89,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 3
test/testver.c

@@ -19,9 +19,6 @@
 
 int main(int argc, char *argv[])
 {
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     if (argc > 1) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "USAGE: %s", argv[0]);
         return 1;

+ 0 - 3
test/testvulkan.c

@@ -1107,9 +1107,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Set Vulkan parameters */
     state->window_flags |= SDL_WINDOW_VULKAN;
     state->skip_renderer = 1;

+ 1 - 3
test/testwm.c

@@ -264,9 +264,7 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
+    /* Parse commandline */
     if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
         SDLTest_CommonQuit(state);
         return 1;

+ 0 - 3
test/testyuv.c

@@ -305,9 +305,6 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
     /* Parse commandline */
     for (i = 1; i < argc;) {
         int consumed;

+ 0 - 9
test/torturethread.c

@@ -89,15 +89,6 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Enable standard application logging */
-    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
-    /* Load the SDL library */
-    if (!SDL_Init(0)) {
-        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
-        return 1;
-    }
-
     if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
         SDL_Quit();
         SDLTest_CommonDestroyState(state);