Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Add screenshot capturing for ensure/assert events on Android ([#1097](https://github.com/getsentry/sentry-unreal/pull/1097))
- Add level-specific logging methods (LogDebug, LogInfo, LogWarning, LogError, LogFatal) to match other Sentry SDKs ([#1110](https://github.com/getsentry/sentry-unreal/pull/1110))

### Fixes

Expand Down
21 changes: 20 additions & 1 deletion plugin-dev/Source/Sentry/Private/SentryOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,26 @@ void FSentryOutputDevice::Serialize(const TCHAR* V, ELogVerbosity::Type Verbosit

if (bIsStructuredLoggingEnabled && ShouldForwardToStructuredLogging(CategoryString, Level))
{
SentrySubsystem->AddLog(Message, Level, CategoryString);
// Use level-specific logging methods
switch (Level)
{
case ESentryLevel::Info:
SentrySubsystem->LogInfo(Message, CategoryString);
break;
case ESentryLevel::Warning:
SentrySubsystem->LogWarning(Message, CategoryString);
break;
case ESentryLevel::Error:
SentrySubsystem->LogError(Message, CategoryString);
break;
case ESentryLevel::Fatal:
SentrySubsystem->LogFatal(Message, CategoryString);
break;
case ESentryLevel::Debug:
default:
SentrySubsystem->LogDebug(Message, CategoryString);
break;
}

// If we don't want to also send breadcrumbs when structured logging is enabled, return early
if (!bSendBreadcrumbsWithStructuredLogging)
Expand Down
52 changes: 50 additions & 2 deletions plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void USentrySubsystem::AddBreadcrumbWithParams(const FString& Message, const FSt
SubsystemNativeImpl->AddBreadcrumbWithParams(Message, Category, Type, Data, Level);
}

void USentrySubsystem::AddLog(const FString& Body, ESentryLevel Level, const FString& Category)
void USentrySubsystem::LogDebug(const FString& Message, const FString& Category)
{
check(SubsystemNativeImpl);

Expand All @@ -247,7 +247,55 @@ void USentrySubsystem::AddLog(const FString& Body, ESentryLevel Level, const FSt
return;
}

SubsystemNativeImpl->AddLog(Body, Level, Category);
SubsystemNativeImpl->AddLog(Message, ESentryLevel::Debug, Category);
}

void USentrySubsystem::LogInfo(const FString& Message, const FString& Category)
{
check(SubsystemNativeImpl);

if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled())
{
return;
}

SubsystemNativeImpl->AddLog(Message, ESentryLevel::Info, Category);
}

void USentrySubsystem::LogWarning(const FString& Message, const FString& Category)
{
check(SubsystemNativeImpl);

if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled())
{
return;
}

SubsystemNativeImpl->AddLog(Message, ESentryLevel::Warning, Category);
}

void USentrySubsystem::LogError(const FString& Message, const FString& Category)
{
check(SubsystemNativeImpl);

if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled())
{
return;
}

SubsystemNativeImpl->AddLog(Message, ESentryLevel::Error, Category);
}

void USentrySubsystem::LogFatal(const FString& Message, const FString& Category)
{
check(SubsystemNativeImpl);

if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled())
{
return;
}

SubsystemNativeImpl->AddLog(Message, ESentryLevel::Fatal, Category);
}

void USentrySubsystem::ClearBreadcrumbs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void SentryBeforeLogHandlerSpec::Define()
TestEqual("Handler received correct level", LogData->GetLevel(), TestLevel);
});

SentrySubsystem->AddLog(TestBody, TestLevel, TestCategory);
SentrySubsystem->LogWarning(TestBody, TestCategory);

TestTrue("BeforeLogHandler should be called", bHandlerCalled);

Expand Down
45 changes: 40 additions & 5 deletions plugin-dev/Source/Sentry/Public/SentrySubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,49 @@ class SENTRY_API USentrySubsystem : public UEngineSubsystem
ESentryLevel Level = ESentryLevel::Info);

/**
* Add a structured log message to Sentry.
* Add a debug level structured log message to Sentry.
*
* @param Body Log body to add.
* @param Level Log level.
* @param Category Optional category to prepend to the body.
* @param Message Log message to add.
* @param Category Optional category to prepend to the message.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry")
void AddLog(const FString& Body, ESentryLevel Level, const FString& Category = TEXT("LogSentrySdk"));
void LogDebug(const FString& Message, const FString& Category = TEXT("LogSentrySdk"));

/**
* Add an info level structured log message to Sentry.
*
* @param Message Log message to add.
* @param Category Optional category to prepend to the message.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry")
void LogInfo(const FString& Message, const FString& Category = TEXT("LogSentrySdk"));

/**
* Add a warning level structured log message to Sentry.
*
* @param Message Log message to add.
* @param Category Optional category to prepend to the message.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry")
void LogWarning(const FString& Message, const FString& Category = TEXT("LogSentrySdk"));

/**
* Add an error level structured log message to Sentry.
*
* @param Message Log message to add.
* @param Category Optional category to prepend to the message.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry")
void LogError(const FString& Message, const FString& Category = TEXT("LogSentrySdk"));

/**
* Add a fatal level structured log message to Sentry.
*
* @param Message Log message to add.
* @param Category Optional category to prepend to the message.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry")
void LogFatal(const FString& Message, const FString& Category = TEXT("LogSentrySdk"));

/**
* Clear all breadcrumbs of the current Scope.
Expand Down