Procházet zdrojové kódy

Use CE_LOGE* to log errors

Daniele Bartolini před 10 roky
rodič
revize
4571eb436d

+ 13 - 8
src/core/error/error.cpp

@@ -5,24 +5,29 @@
 
 #include "error.h"
 #include "stacktrace.h"
+#include "log.h"
 #include <stdlib.h>
-#include <stdio.h>
 #include <stdarg.h>
 
 namespace crown
 {
 namespace error
 {
-	void abort(const char* file, int line, const char* message, ...)
+	static void abort(const char* file, int line, const char* format, va_list args)
 	{
-		va_list ap;
-		va_start(ap, message);
-		vprintf(message, ap);
-		va_end(ap);
-		printf("\tIn: %s:%d\n", file, line);
-		printf("Stacktrace:\n");
+		CE_LOGEV(format, args);
+		CE_LOGE("\tIn: %s:%d", file, line);
+		CE_LOGE("Stacktrace:");
 		print_callstack();
 		exit(EXIT_FAILURE);
 	}
+
+	void abort(const char* file, int line, const char* format, ...)
+	{
+		va_list args;
+		va_start(args, format);
+		abort(file, line, format, args);
+		va_end(args);
+	}
 } // namespace error
 } // namespace crown

+ 1 - 1
src/core/error/error.h

@@ -13,7 +13,7 @@ namespace error
 {
 	/// Aborts the program execution logging an error message and the stacktrace if
 	/// the platform supports it.
-	void abort(const char* file, int line, const char* message, ...);
+	void abort(const char* file, int line, const char* format, ...);
 } // namespace error
 } // namespace crown
 

+ 3 - 3
src/core/error/stacktrace_linux.cpp

@@ -9,7 +9,7 @@
 
 #include "macros.h"
 #include "string_utils.h"
-#include <stdio.h>
+#include "log.h"
 #include <stdlib.h>
 #include <cxxabi.h>
 #include <execinfo.h>
@@ -64,7 +64,7 @@ void print_callstack()
 			char line[256];
 			memset(line, 0, sizeof(line));
 
-			printf("\t[%d] %s: (%s)+%s in %s\n"
+			CE_LOGE("\t[%d] %s: (%s)+%s in %s"
 				, i
 				, msg
 				, (demangle_ok == 0 ? real_name : mangled_name)
@@ -77,7 +77,7 @@ void print_callstack()
 		// otherwise, print the whole line
 		else
 		{
-			printf("\t[%d] %s\n", i, msg);
+			CE_LOGE("\t[%d] %s", i, msg);
 		}
 	}
 	free(messages);

+ 3 - 3
src/core/error/stacktrace_windows.cpp

@@ -7,9 +7,9 @@
 
 #if CROWN_PLATFORM_WINDOWS
 
+#include "log.h"
 #include <windows.h>
 #include <dbghelp.h>
-#include <stdio.h>
 
 namespace crown
 {
@@ -77,9 +77,9 @@ void print_callstack()
 		res = res && SymFromAddr(GetCurrentProcess(), stack.AddrPC.Offset, 0, sym);
 
 		if (res == TRUE)
-			printf("\t[%i] %s (%s:%d)\n", num, sym->Name, line.FileName, line.LineNumber);
+			CE_LOGE("\t[%i] %s (%s:%d)", num, sym->Name, line.FileName, line.LineNumber);
 		else
-			printf("\t[%i] 0x%p\n", num, stack.AddrPC.Offset);
+			CE_LOGE("\t[%i] 0x%p", num, stack.AddrPC.Offset);
 	}
 
 	SymCleanup(GetCurrentProcess());