瀏覽代碼

AK: Colorize log message for failed assertions

The log message can be hard to spot in a sea of debug messages. Colorize
it to make the message more immediately pop out.
Timothy Flynn 1 年之前
父節點
當前提交
0eaf13bae3
共有 1 個文件被更改,包括 11 次插入1 次删除
  1. 11 1
      AK/Assertions.cpp

+ 11 - 1
AK/Assertions.cpp

@@ -89,7 +89,17 @@ extern "C" {
 
 void ak_verification_failed(char const* message)
 {
-    ERRORLN("VERIFICATION FAILED: {}", message);
+#    if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
+    bool colorize_output = true;
+#    else
+    bool colorize_output = isatty(STDERR_FILENO) == 1;
+#    endif
+
+    if (colorize_output)
+        ERRORLN("\033[31;1mVERIFICATION FAILED\033[0m: {}", message);
+    else
+        ERRORLN("VERIFICATION FAILED: {}", message);
+
 #    if defined(EXECINFO_BACKTRACE)
     dump_backtrace();
 #    endif