Skip to content

Commit 4b5cbc3

Browse files
authored
docs(godot): Structured logging (#15287)
1 parent 0f2861d commit 4b5cbc3

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Set Up Logs
3+
sidebar_title: Logs
4+
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
5+
sidebar_order: 5600
6+
---
7+
8+
With Sentry Structured Logs, you can send text-based log information from your Godot 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.
9+
10+
## Requirements
11+
12+
<PlatformContent includePath="logs/requirements" />
13+
14+
## Setup
15+
16+
<PlatformContent includePath="logs/setup" />
17+
18+
## Usage
19+
20+
<PlatformContent includePath="logs/usage" />
21+
22+
## Options
23+
24+
<PlatformContent includePath="logs/options" />
25+
26+
## Default Attributes
27+
28+
<PlatformContent includePath="logs/default-attributes" />
29+
30+
## Troubleshooting
31+
32+
<PlatformContent includePath="logs/troubleshooting" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The Godot SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
2+
3+
<Include name="logs/default-attributes/core" />
4+
5+
<Include name="logs/default-attributes/user-mobile" />
6+
7+
<Include name="logs/default-attributes/integration" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### before_send_log
2+
3+
To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` option.
4+
5+
```GDScript
6+
SentrySDK.init(func(options: SentryOptions) -> void:
7+
options.experimental.enable_logs = true
8+
options.experimental.before_send_log = _before_send_log
9+
)
10+
11+
func _before_send_log(log_entry: SentryLog) -> SentryLog:
12+
# Filter junk.
13+
if log_entry.body == "Junk message":
14+
return null
15+
# Remove sensitive information from log messages.
16+
log_entry.body = log_entry.body.replace("Bruno", "REDACTED")
17+
# Add custom attributes.
18+
log_entry.set_attribute("current_scene", current_scene.name)
19+
return log_entry
20+
```
21+
22+
The `before_send_log` function receives a `SentryLog` object, and should return either the same log object, with or without modifications, or `null` if you want to discard it.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logs for Godot Engine are supported in Sentry Godot SDK version `1.1.0` and above.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
To enable logging in your Godot project, you need to configure the Sentry SDK with Logs enabled.
2+
3+
### Project Settings Configuration
4+
5+
1. Open **Project Settings** in Godot, and navigate to **Sentry > Experimental**.
6+
2. Turn on the **Enable Logs** option.
7+
8+
### Programmatic Configuration
9+
10+
Alternatively, you can enable logs programmatically when initializing the SDK:
11+
12+
```GDScript
13+
SentrySDK.init(func(options: SentryOptions) -> void:
14+
options.experimental.enable_logs = true
15+
)
16+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Performance Considerations
2+
3+
- Logs are sent asynchronously to avoid impacting game performance.
4+
- Consider disabling debug level logs in production to avoid excessive log volume.
5+
- `before_send_log` callback is executed synchronously, so keep processing lightweight.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySDK.logger` APIs.
2+
3+
The `SentrySDK.logger` exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.
4+
5+
```GDScript
6+
SentrySDK.logger.trace("Initialized inventory database")
7+
SentrySDK.logger.debug("Player inventory updated")
8+
SentrySDK.logger.info("Level loaded successfully")
9+
SentrySDK.logger.warn("Item configuration not found")
10+
SentrySDK.logger.error("Failed to save game state")
11+
SentrySDK.logger.fatal("Inventory data corrupted")
12+
```
13+
14+
<Alert level="info">
15+
16+
Support for log attributes and string interpolation will be added in future releases.
17+
18+
</Alert>
19+
20+
### Godot Logging Integration
21+
22+
When the feature is enabled, the SDK automatically captures Godot messages, warnings, and errors as logs. You can use `print()`, `push_warning()`, and `push_error()` as usual. These show up as `info`, `warning`, and `error` logs. The SDK also turns runtime errors and warnings into events based on your configuration.

0 commit comments

Comments
 (0)