From 13cc6eb7b928d43fc5061e1c98c4ac2247525577 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 26 Feb 2021 11:50:05 +0100 Subject: [PATCH] Cleanup DebugLog internal calls --- Source/Engine/Debug/DebugLog.cpp | 72 +------------------ Source/Engine/Debug/DebugLog.h | 7 -- .../InternalCalls/EngineInternalCalls.cpp | 60 +++++++++++++++- 3 files changed, 60 insertions(+), 79 deletions(-) diff --git a/Source/Engine/Debug/DebugLog.cpp b/Source/Engine/Debug/DebugLog.cpp index bf1da8d7d..55c17b7f0 100644 --- a/Source/Engine/Debug/DebugLog.cpp +++ b/Source/Engine/Debug/DebugLog.cpp @@ -1,12 +1,7 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #include "DebugLog.h" -#include "Engine/Core/Log.h" -#include "Engine/Scripting/InternalCalls.h" -#include "Engine/Scripting/ScriptingObject.h" -#include "Engine/Scripting/MException.h" #include "Engine/Scripting/Scripting.h" -#include "Engine/Scripting/ScriptingType.h" #include "Engine/Scripting/BinaryModule.h" #include "Engine/Scripting/MainThreadManagedInvokeAction.h" #include "Engine/Scripting/ManagedCLR/MDomain.h" @@ -16,70 +11,7 @@ #include #include -namespace DebugLogHandlerInternal -{ - void LogWrite(LogType level, MonoString* msgObj) - { - StringView msg; - MUtils::ToString(msgObj, msg); - Log::Logger::Write(level, msg); - } - - void Log(LogType level, MonoString* msgObj, ScriptingObject* obj, MonoString* stackTrace) - { - if (msgObj == nullptr) - return; - - // Get info - StringView msg; - MUtils::ToString(msgObj, msg); - //const String objName = obj ? obj->ToString() : String::Empty; - - // Send event - // TODO: maybe option for build to threat warnings and errors as fatal errors? - //const String logMessage = String::Format(TEXT("Debug:{1} {2}"), objName, *msg); - Log::Logger::Write(level, msg); - } - - void LogException(MonoException* exception, ScriptingObject* obj) - { - if (exception == nullptr) - return; - - // Get info - MException ex(exception); - String objName = obj ? obj->ToString() : String::Empty; - - // Print exception including inner exceptions - // TODO: maybe option for build to threat warnings and errors as fatal errors? - ex.Log(LogType::Warning, objName.GetText()); - } -} - -namespace FlaxLogWriterInternal -{ - void WriteStringToLog(MonoString* msg) - { - if (msg == nullptr) - return; - - auto msgStr = (Char*)mono_string_to_utf16(msg); - LOG_STR(Info, msgStr); - } -} - -void DebugLog::RegisterInternalCalls() -{ - // DebugLogHandler - ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogWrite", &DebugLogHandlerInternal::LogWrite); - ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_Log", &DebugLogHandlerInternal::Log); - ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogException", &DebugLogHandlerInternal::LogException); - - // FlaxLogWriter - ADD_INTERNAL_CALL("FlaxEngine.FlaxLogWriter::Internal_WriteStringToLog", &FlaxLogWriterInternal::WriteStringToLog); -} - -namespace DebugLogImpl +namespace Impl { MMethod* Internal_SendLog = nullptr; MMethod* Internal_SendLogException = nullptr; @@ -87,7 +19,7 @@ namespace DebugLogImpl CriticalSection Locker; } -using namespace DebugLogImpl; +using namespace Impl; void ClearMethods(MAssembly*) { diff --git a/Source/Engine/Debug/DebugLog.h b/Source/Engine/Debug/DebugLog.h index 6ef7f8242..fd05bee7c 100644 --- a/Source/Engine/Debug/DebugLog.h +++ b/Source/Engine/Debug/DebugLog.h @@ -10,13 +10,6 @@ /// class FLAXENGINE_API DebugLog { -public: - - /// - /// Registers the internal calls to managed code. - /// - static void RegisterInternalCalls(); - public: /// diff --git a/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp b/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp index 0e06179fa..144eb6c86 100644 --- a/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp +++ b/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp @@ -1,9 +1,10 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #include "Engine/Platform/FileSystem.h" -#include "Engine/Debug/DebugLog.h" #include "Engine/Animations/Graph/AnimGraph.h" #include "Engine/Scripting/InternalCalls.h" +#include "Engine/Scripting/MException.h" +#include "Engine/Scripting/ManagedCLR/MUtils.h" namespace UtilsInternal { @@ -13,9 +14,64 @@ namespace UtilsInternal } } +namespace DebugLogHandlerInternal +{ + void LogWrite(LogType level, MonoString* msgObj) + { + StringView msg; + MUtils::ToString(msgObj, msg); + Log::Logger::Write(level, msg); + } + + void Log(LogType level, MonoString* msgObj, ScriptingObject* obj, MonoString* stackTrace) + { + if (msgObj == nullptr) + return; + + // Get info + StringView msg; + MUtils::ToString(msgObj, msg); + //const String objName = obj ? obj->ToString() : String::Empty; + + // Send event + // TODO: maybe option for build to threat warnings and errors as fatal errors? + //const String logMessage = String::Format(TEXT("Debug:{1} {2}"), objName, *msg); + Log::Logger::Write(level, msg); + } + + void LogException(MonoException* exception, ScriptingObject* obj) + { + if (exception == nullptr) + return; + + // Get info + MException ex(exception); + const String objName = obj ? obj->ToString() : String::Empty; + + // Print exception including inner exceptions + // TODO: maybe option for build to threat warnings and errors as fatal errors? + ex.Log(LogType::Warning, objName.GetText()); + } +} + +namespace FlaxLogWriterInternal +{ + void WriteStringToLog(MonoString* msgObj) + { + if (msgObj == nullptr) + return; + StringView msg; + MUtils::ToString(msgObj, msg); + LOG_STR(Info, msg); + } +} + void registerFlaxEngineInternalCalls() { - DebugLog::RegisterInternalCalls(); AnimGraphExecutor::initRuntime(); ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCopy", &UtilsInternal::MemoryCopy); + ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogWrite", &DebugLogHandlerInternal::LogWrite); + ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_Log", &DebugLogHandlerInternal::Log); + ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogException", &DebugLogHandlerInternal::LogException); + ADD_INTERNAL_CALL("FlaxEngine.FlaxLogWriter::Internal_WriteStringToLog", &FlaxLogWriterInternal::WriteStringToLog); }