Add support for capturing stack trace of called DebugLog from C++

This commit is contained in:
Wojtek Figat
2021-02-26 13:58:42 +01:00
parent a45b71617d
commit ff70c16051
5 changed files with 49 additions and 20 deletions

View File

@@ -43,7 +43,7 @@ bool CacheMethods()
if (!debugLogHandlerClass)
return false;
Internal_SendLog = debugLogHandlerClass->GetMethod("Internal_SendLog", 2);
Internal_SendLog = debugLogHandlerClass->GetMethod("Internal_SendLog", 3);
if (!Internal_SendLog)
return false;
@@ -60,7 +60,7 @@ bool CacheMethods()
return false;
}
void DebugLog::Log(LogType type, const String& message)
void DebugLog::Log(LogType type, const StringView& message)
{
if (CacheMethods())
return;
@@ -69,15 +69,18 @@ void DebugLog::Log(LogType type, const String& message)
MainThreadManagedInvokeAction::ParamsBuilder params;
params.AddParam(type);
params.AddParam(message, scriptsDomain->GetNative());
#if BUILD_RELEASE
params.AddParam(StringView::Empty, scriptsDomain->GetNative());
#else
const String stackTrace = Platform::GetStackTrace(1);
params.AddParam(stackTrace, scriptsDomain->GetNative());
#endif
MainThreadManagedInvokeAction::Invoke(Internal_SendLog, params);
}
void DebugLog::LogException(MonoObject* exceptionObject)
{
if (exceptionObject == nullptr)
return;
if (CacheMethods())
if (exceptionObject == nullptr || CacheMethods())
return;
MainThreadManagedInvokeAction::ParamsBuilder params;

View File

@@ -17,13 +17,13 @@ public:
/// </summary>
/// <param name="type">The message type.</param>
/// <param name="message">The message.</param>
static void Log(LogType type, const String& message);
static void Log(LogType type, const StringView& message);
/// <summary>
/// A variant of Debug.Log that logs a warning message to the console.
/// </summary>
/// <param name="message">The text message to display.</param>
FORCE_INLINE static void Log(const String& message)
FORCE_INLINE static void Log(const StringView& message)
{
Log(LogType::Info, message);
}
@@ -32,7 +32,7 @@ public:
/// A variant of Debug.Log that logs a warning message to the console.
/// </summary>
/// <param name="message">The text message to display.</param>
FORCE_INLINE static void LogWarning(const String& message)
FORCE_INLINE static void LogWarning(const StringView& message)
{
Log(LogType::Warning, message);
}
@@ -41,7 +41,7 @@ public:
/// A variant of Debug.Log that logs a error message to the console.
/// </summary>
/// <param name="message">The text message to display.</param>
FORCE_INLINE static void LogError(const String& message)
FORCE_INLINE static void LogError(const StringView& message)
{
Log(LogType::Error, message);
}