Cleanup DebugLog internal calls

This commit is contained in:
Wojtek Figat
2021-02-26 11:50:05 +01:00
parent e9adaa7c87
commit 13cc6eb7b9
3 changed files with 60 additions and 79 deletions

View File

@@ -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 <ThirdParty/mono-2.0/mono/metadata/exception.h>
#include <ThirdParty/mono-2.0/mono/metadata/appdomain.h>
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*)
{

View File

@@ -10,13 +10,6 @@
/// </summary>
class FLAXENGINE_API DebugLog
{
public:
/// <summary>
/// Registers the internal calls to managed code.
/// </summary>
static void RegisterInternalCalls();
public:
/// <summary>

View File

@@ -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);
}