-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs (Unreal/logs): Add Logs documentation for Unreal SDK #15064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1333c79
d3169e2
24a8480
82f09d9
3e0be39
6afec2b
bfbdcac
e5566ec
125134e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --- | ||
| title: Set Up Logs | ||
| sidebar_title: Logs | ||
| description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry." | ||
| sidebar_order: 5600 | ||
| --- | ||
|
|
||
| With Sentry Structured Logs, you can send text-based log information from your Unreal Engine applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes. | ||
|
|
||
| ## Requirements | ||
|
|
||
| <PlatformContent includePath="logs/requirements" /> | ||
|
|
||
| ## Setup | ||
|
|
||
| <PlatformContent includePath="logs/setup" /> | ||
|
|
||
| ## Usage | ||
|
|
||
| <PlatformContent includePath="logs/usage" /> | ||
|
|
||
| ## Options | ||
|
|
||
| <PlatformContent includePath="logs/options" /> | ||
|
|
||
| ## Default Attributes | ||
|
|
||
| <PlatformContent includePath="logs/default-attributes" /> | ||
|
|
||
| ## Performance Considerations | ||
|
|
||
| - Logs are sent asynchronously to avoid impacting game performance | ||
| - Consider disabling Debug level logs in production to avoid excessive log volume | ||
| - Each severity level can be individually controlled to fine-tune what gets sent to Sentry | ||
| - Use categories to organize logs and make them easier to search and filter | ||
| - Before-log handlers are executed synchronously, so keep processing lightweight |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The Unreal Engine SDK automatically sets several default attributes on all log entries to provide context and improve debugging: | ||
|
|
||
| <Include name="logs/default-attributes/core" /> | ||
|
|
||
| <Include name="logs/default-attributes/user-mobile" /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ## Configuration Options | ||
|
|
||
| The following configuration options are available for Sentry Logs in Unreal Engine: | ||
|
|
||
| | Option | Description | Default | | ||
| |--------|-------------|------------| | ||
| | **Enable Structured Logging** | Master toggle for the structured logging feature | `false` | | ||
| | **Enable Debug Logs** | Forward Debug level UE_LOG calls to Sentry | `false` | | ||
| | **Enable Info Logs** | Forward Info level UE_LOG calls to Sentry | `false` | | ||
| | **Enable Warning Logs** | Forward Warning level UE_LOG calls to Sentry | `true` | | ||
| | **Enable Error Logs** | Forward Error level UE_LOG calls to Sentry | `true` | | ||
| | **Enable Fatal Logs** | Forward Fatal level UE_LOG calls to Sentry | `true` | | ||
| | **Send Logs As Breadcrumbs** | Send UE_LOG calls BOTH as Logs and as Breadcrumbs, instead of just Logs | `false` | | ||
| | **Log Category Filter** | Array of log categories to include (empty = all categories) | Empty | | ||
| | **Before Log Callback** | Handler to modify or filter log events before sending | None | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Logs for Unreal Engine are supported in Sentry Unreal Engine SDK version `1.2.0` and above. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| To enable logging in your Unreal Engine project, you need to configure the Sentry SDK with structured logging enabled. | ||
|
|
||
| ### Project Settings Configuration | ||
|
|
||
| 1. Open your project settings: **Project Settings > Plugins > Sentry** | ||
| 2. Check the **Enable Structured Logging** option | ||
|
|
||
| ### Programmatic Configuration | ||
|
|
||
| Alternatively, you can enable logging programmatically when initializing the SDK: | ||
|
|
||
| ```cpp | ||
| #include "SentrySubsystem.h" | ||
|
|
||
| void ConfigureSentryWithLogs() | ||
| { | ||
| USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>(); | ||
|
|
||
| // Create settings with logging enabled | ||
| SentrySubsystem->InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateLambda([=](USentrySettings* Settings) | ||
| { | ||
| Settings->EnableStructuredLogging = true; | ||
| })); | ||
| } | ||
| ``` | ||
|
|
||
| ### Advanced Configuration Options | ||
|
|
||
| #### Automatic Unreal Engine Log Forwarding | ||
|
|
||
| You can configure the SDK to automatically forward Unreal Engine's native `UE_LOG` calls to Sentry based on the enabled severity levels: | ||
|
|
||
| ```cpp | ||
| USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>(); | ||
|
|
||
| // Configure automatic log forwarding programmatically | ||
| SentrySubsystem->InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateLambda([=](USentrySettings* Settings) | ||
| { | ||
| Settings->EnableStructuredLogging = true; | ||
|
|
||
| // Enable specific severity levels for UE_LOG forwarding | ||
| Settings->EnableDebugLogs = false; | ||
| Settings->EnableInfoLogs = true; | ||
| Settings->EnableWarningLogs = true; | ||
| Settings->EnableErrorLogs = true; | ||
| Settings->EnableFatalLogs = true; | ||
|
|
||
| Settings->bSendBreadcrumbsWithStructuredLogging = false; // Send as structured logs instead of breadcrumbs | ||
| })); | ||
| ``` | ||
|
|
||
| #### Log Category Filtering | ||
|
|
||
| You can filter which log categories are sent to Sentry: | ||
|
|
||
| ```cpp | ||
| // Configure category filtering | ||
| USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>(); | ||
|
|
||
| // Create settings with logging enabled | ||
| SentrySubsystem->InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateLambda([=](USentrySettings* Settings) | ||
| { | ||
| Settings->EnableStructuredLogging = true; | ||
|
|
||
| // Only forward logs from specific categories | ||
| TArray<FString> AllowedCategories; | ||
| AllowedCategories.Add(TEXT("LogGameFlow")); | ||
| AllowedCategories.Add(TEXT("LogPlayerSystem")); | ||
| AllowedCategories.Add(TEXT("LogSentrySdk")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we don't add this to the snippet and end up with users copy-pasting this into their game. 😁 |
||
| Settings->LogCategoryFilter = AllowedCategories; | ||
|
|
||
| })); | ||
| ``` | ||
|
|
||
| #### Before-Log Handler | ||
|
|
||
| To filter logs, or update them before they are sent to Sentry, you can create a custom before-log handler class. | ||
|
|
||
| <Alert level="info"> | ||
| Logging additional messages in the BeforeLog handler can cause recursive call of the handler, resulting in a stack overflow! | ||
| </Alert> | ||
|
|
||
| ```cpp | ||
| UCLASS() | ||
| class UCustomLogFilter : public USentryBeforeLogHandler | ||
| { | ||
| GENERATED_BODY() | ||
| public: | ||
| virtual USentryLogEvent* HandleBeforeLog_Implementation(USentryLogEvent* LogEvent) override | ||
| { | ||
| // Filter out all debug logs | ||
| if (LogEvent->GetLevel() == ESentryLevel::Debug) | ||
| { | ||
| return nullptr; // Return null to prevent sending | ||
| } | ||
|
|
||
| // Filter out logs based on message content | ||
| if (LogEvent->GetBody().Contains(TEXT("Sensitive"))) | ||
| { | ||
| return nullptr; // Filter out sensitive logs | ||
| } | ||
|
|
||
| // Filter based on specific categories | ||
| if (LogEvent->GetBody().Contains(TEXT("Password")) || | ||
| LogEvent->GetBody().Contains(TEXT("Token"))) | ||
| { | ||
| return nullptr; // Filter out authentication-related logs | ||
| } | ||
|
|
||
| return LogEvent; // Return modified event | ||
| } | ||
| }; | ||
|
|
||
| // Configure settings using delegate | ||
| FConfigureSettingsDelegate SettingsDelegate; | ||
| SettingsDelegate.BindDynamic(this, &USomeClass::HandleSettingsDelegate); | ||
|
|
||
| void USomeClass::HandleSettingsDelegate(USentrySettings* Settings) | ||
| { | ||
| // Enable structured logging | ||
| Settings->EnableStructuredLogging = true; | ||
|
|
||
| // Configure individual severity levels | ||
| Settings->EnableDebugLogs = false; | ||
| Settings->EnableInfoLogs = true; | ||
| Settings->EnableWarningLogs = true; | ||
| Settings->EnableErrorLogs = true; | ||
| Settings->EnableFatalLogs = true; | ||
|
|
||
| // Set custom before-log handler | ||
| Settings->BeforeLogCallback = UCustomLogFilter::StaticClass(); | ||
| } | ||
|
|
||
| // Initialize with settings delegate | ||
| USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>(); | ||
| SentrySubsystem->InitializeWithSettings(SettingsDelegate); | ||
| ``` | ||
|
|
||
| The `HandleBeforeLog_Implementation` method receives a `USentryLog` object, and should return the log event if you want it to be sent to Sentry, or `nullptr` if you want to discard it. | ||
|
|
||
| The `USentryLog` object has the following methods: | ||
| - `GetLevel()`: Returns the severity level of the log (`ESentryLevel`) | ||
| - `GetBody()`: Returns the formatted log message (`FString`) | ||
| - `SetLevel(ESentryLevel Level)`: Sets the Level of the Log Event | ||
| - `SetBody(FString& Body)`: Sets the Body of the Log Event | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| Once logging is enabled, you can send log messages to Sentry using the `AddLog` method. | ||
|
|
||
| ## Basic Logging | ||
|
|
||
| ```cpp | ||
| #include "SentrySubsystem.h" | ||
|
|
||
| void SendLogs() | ||
| { | ||
| USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>(); | ||
|
|
||
| // Send a simple log message | ||
| SentrySubsystem->AddLog(TEXT("User completed tutorial"), ESentryLevel::Info); | ||
|
|
||
| // Send a log message with category | ||
| SentrySubsystem->AddLog(TEXT("Failed to load texture asset"), ESentryLevel::Warning, TEXT("AssetLoading")); | ||
|
|
||
| // Send an error log | ||
| SentrySubsystem->AddLog(TEXT("Database connection failed"), ESentryLevel::Error, TEXT("Database")); | ||
| } | ||
| ``` | ||
|
|
||
| ## Log Levels | ||
|
|
||
| Sentry Logs supports the following log levels: | ||
|
|
||
| | Unreal ESentryLevel | Sentry Logs UI Severity | | ||
| | --- | --- | | ||
| | Debug | DEBUG | | ||
| | Info | INFO | | ||
| | Warning | WARN | | ||
| | Error | ERROR | | ||
| | Fatal | FATAL | | ||
|
|
||
| ```cpp | ||
| // Examples of different log levels | ||
| SentrySubsystem->AddLog(TEXT("Player position updated"), ESentryLevel::Debug, TEXT("Player")); | ||
| SentrySubsystem->AddLog(TEXT("Level loaded successfully"), ESentryLevel::Info, TEXT("GameFlow")); | ||
| SentrySubsystem->AddLog(TEXT("Low memory warning"), ESentryLevel::Warning, TEXT("Performance")); | ||
| SentrySubsystem->AddLog(TEXT("Failed to save game data"), ESentryLevel::Error, TEXT("SaveSystem")); | ||
| SentrySubsystem->AddLog(TEXT("Critical system failure"), ESentryLevel::Fatal, TEXT("System")); | ||
| ``` | ||
|
|
||
| ## Automatic UE_LOG Integration | ||
|
|
||
| When structured logging is enabled with the appropriate severity levels, the SDK can automatically capture Unreal Engine's native `UE_LOG` calls: | ||
|
|
||
| ```cpp | ||
| // Standard Unreal Engine logging - automatically captured when severity levels are enabled | ||
| UE_LOG(LogGameFlow, Warning, TEXT("Player health is critically low: %d"), PlayerHealth); | ||
| UE_LOG(LogAssets, Error, TEXT("Failed to load texture: %s"), *TexturePath); | ||
| UE_LOG(LogTemp, Log, TEXT("Debug information")); // Only sent if EnableInfoLogs = true | ||
| ``` | ||
|
|
||
| You can configure whether these logs are sent as: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's the "sent" that reads confusing to me. "Sent as strucutured logs" vs "captured and added to an event"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this is correct, we can send these logs either as Structured logs or as Breadcrumbs (was behavior until now). So from now on UE_LOGs should come as Logs, and users can still opt-back for the Breadcrumbs option too. |
||
| - **Structured Logs**: Full log entries with searchable attributes | ||
| - **Breadcrumbs**: Contextual information attached to errors (useful for debugging) | ||
|
|
||
| ## Blueprint Support | ||
|
|
||
| You can also use Sentry Logs from Blueprints by calling the **Add Log** function: | ||
|
|
||
| 1. Add a **Add Log** node to your Blueprint | ||
| 2. Set the **Body** parameter to your log message | ||
| 3. Choose the appropriate **Level** from the dropdown | ||
| 4. Optionally set a **Category** for better organization | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trips me up. To me this reads like I can send logs as breadcrumbs. Like I have a choice between structured logs and breadcrumbs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly correct, up until now all UE_LOGs were being sent as Breadcrumbs. With the new feature implemented we still allow users to chose either/or both.