ソースを参照

Use default log output also when there is no system interface installed

This ensures that log messages are submitted to the same stream output before and after installing the default provided system interface. In particular, the output from MSVC is given in its debug output.
Michael Ragazzon 1 年間 前
コミット
ac8e1f2752

+ 2 - 0
CMake/FileList.cmake

@@ -76,6 +76,7 @@ set(Core_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/ReplacedFormattingContext.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/TableFormattingContext.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/TableFormattingDetails.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/LogDefault.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Memory.h
     ${PROJECT_SOURCE_DIR}/Source/Core/PluginRegistry.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Pool.h
@@ -352,6 +353,7 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/TableFormattingContext.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/TableFormattingDetails.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Log.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/LogDefault.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Math.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Memory.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/MeshUtilities.cpp

+ 3 - 2
Source/Core/Log.cpp

@@ -30,6 +30,7 @@
 #include "../../Include/RmlUi/Core/Core.h"
 #include "../../Include/RmlUi/Core/StringUtilities.h"
 #include "../../Include/RmlUi/Core/SystemInterface.h"
+#include "LogDefault.h"
 #include <stdarg.h>
 #include <stdio.h>
 
@@ -54,7 +55,7 @@ void Log::Message(Log::Type type, const char* fmt, ...)
 	if (SystemInterface* system_interface = GetSystemInterface())
 		system_interface->LogMessage(type, buffer);
 	else
-		puts(buffer);
+		LogDefault::LogMessage(type, buffer);
 }
 
 void Log::ParseError(const String& filename, int line_number, const char* fmt, ...)
@@ -87,7 +88,7 @@ bool Assert(const char* msg, const char* file, int line)
 	if (SystemInterface* system_interface = GetSystemInterface())
 		result = system_interface->LogMessage(Log::LT_ASSERT, message);
 	else
-		puts(message.c_str());
+		result = LogDefault::LogMessage(Log::LT_ASSERT, message);
 
 	return result;
 }

+ 71 - 0
Source/Core/LogDefault.cpp

@@ -0,0 +1,71 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019-2023 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "LogDefault.h"
+#include "../../Include/RmlUi/Core/StringUtilities.h"
+
+#ifdef RMLUI_PLATFORM_WIN32
+	#include <windows.h>
+#else
+	#include <stdio.h>
+#endif
+
+namespace Rml {
+
+#ifdef RMLUI_PLATFORM_WIN32
+bool LogDefault::LogMessage(Log::Type type, const String& message)
+{
+	#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
+	if (type == Log::LT_ASSERT)
+	{
+		String message_user = CreateString(1024, "%s\nWould you like to interrupt execution?", message.c_str());
+
+		// Return TRUE if the user presses NO (continue execution)
+		return (IDNO == MessageBoxA(nullptr, message_user.c_str(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL));
+	}
+	else
+	#endif
+	{
+		OutputDebugStringA(message.c_str());
+		OutputDebugStringA("\r\n");
+	}
+	return true;
+}
+#else
+bool LogDefault::LogMessage(Log::Type /*type*/, const String& message)
+{
+	#ifdef RMLUI_PLATFORM_EMSCRIPTEN
+	puts(message.c_str());
+	#else
+	fprintf(stderr, "%s\n", message.c_str());
+	#endif
+	return true;
+}
+#endif
+
+} // namespace Rml

+ 48 - 0
Source/Core/LogDefault.h

@@ -0,0 +1,48 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019-2023 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef RMLUI_CORE_LOGDEFAULT_H
+#define RMLUI_CORE_LOGDEFAULT_H
+
+#include "../../Include/RmlUi/Core/Log.h"
+#include "../../Include/RmlUi/Core/Types.h"
+
+namespace Rml {
+
+/**
+    Provides a platform-dependent default implementation for message logging.
+ */
+
+class LogDefault {
+public:
+	static bool LogMessage(Log::Type type, const String& message);
+};
+
+} // namespace Rml
+
+#endif

+ 3 - 35
Source/Core/SystemInterface.cpp

@@ -30,12 +30,7 @@
 #include "../../Include/RmlUi/Core/Log.h"
 #include "../../Include/RmlUi/Core/StringUtilities.h"
 #include "../../Include/RmlUi/Core/URL.h"
-
-#ifdef RMLUI_PLATFORM_WIN32
-	#include <windows.h>
-#else
-	#include <stdio.h>
-#endif
+#include "LogDefault.h"
 
 namespace Rml {
 
@@ -45,37 +40,10 @@ SystemInterface::SystemInterface() {}
 
 SystemInterface::~SystemInterface() {}
 
-#ifdef RMLUI_PLATFORM_WIN32
-bool SystemInterface::LogMessage(Log::Type logtype, const String& message)
-{
-	// By default we just send a platform message
-	#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
-	if (logtype == Log::LT_ASSERT)
-	{
-		String message_user = CreateString(1024, "%s\nWould you like to interrupt execution?", message.c_str());
-
-		// Return TRUE if the user presses NO (continue execution)
-		return (IDNO == MessageBoxA(nullptr, message_user.c_str(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL));
-	}
-	else
-	#endif
-	{
-		OutputDebugStringA(message.c_str());
-		OutputDebugStringA("\r\n");
-	}
-	return true;
-}
-#else
-bool SystemInterface::LogMessage(Log::Type /*logtype*/, const String& message)
+bool SystemInterface::LogMessage(Log::Type type, const String& message)
 {
-	#ifdef RMLUI_PLATFORM_EMSCRIPTEN
-	puts(message.c_str());
-	#else
-	fprintf(stderr, "%s\n", message.c_str());
-	#endif
-	return true;
+	return LogDefault::LogMessage(type, message);
 }
-#endif
 
 void SystemInterface::SetMouseCursor(const String& /*cursor_name*/) {}