Skip to content

Commit aa8f26c

Browse files
authored
feat(godot): Document string interpolation and attributes in logging API (#15751)
1 parent 5f719bb commit aa8f26c

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed
Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySDK.logger` APIs.
22

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`.
3+
The `SentrySDK.logger` exposes six methods that you can use to log messages at different log levels: `trace`, `debug`,
4+
`info`, `warn`, `error`, and `fatal`.
45

56
```GDScript
67
SentrySDK.logger.trace("Initialized inventory database")
@@ -11,12 +12,38 @@ SentrySDK.logger.error("Failed to save game state")
1112
SentrySDK.logger.fatal("Inventory data corrupted")
1213
```
1314

14-
<Alert level="info">
15+
The methods support string interpolation using Godot's format strings syntax. The log message can contain format
16+
placeholders (e.g., `%s`, `%d`), and the optional `parameters` array provides values to substitute into placeholders
17+
using Godot's format strings. These will be sent to Sentry as log attributes, and can be searched from within the Logs UI.
1518

16-
Support for log attributes and string interpolation will be added in future releases.
19+
```GDScript
20+
# String interpolation automatically extracts parameters as log attributes
21+
SentrySDK.logger.info("Spawned %d enemies on level %s", [5, "forest_1"])
22+
23+
# This is equivalent to manually specifying attributes:
24+
var message := "Spawned %d enemies on level %s" % [5, "forest_1"]
25+
SentrySDK.logger.info(message, [], {
26+
"sentry.message.template": "Spawned %d enemies on level %s",
27+
"sentry.message.parameter.0": 5,
28+
"sentry.message.parameter.1": "forest_1"
29+
})
30+
```
31+
32+
You can also use structured attributes to provide additional context for your logs. For example, you can add a
33+
`current_scene` attribute to log messages related to currently loaded scene.
34+
35+
```GDScript
36+
# Adding custom attributes, which can be searched from within the Logs UI
37+
SentrySDK.logger.debug("Spawning %s with %d units", ["enemies", 5], {
38+
"current_scene": get_tree().current_scene.scene_file_path,
39+
"wave_id": "main_wave_3"
40+
})
41+
```
1742

18-
</Alert>
43+
Structured attributes support `bool`, `int`, `float`, and `String` data types. Other types will be converted to strings.
1944

2045
### Godot Logging Integration
2146

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.
47+
When the feature is enabled, the SDK automatically captures Godot messages, warnings, and errors as logs. You can use
48+
`print()`, `push_warning()`, and `push_error()` as usual. These show up as `info`, `warning`, and `error` logs. The SDK
49+
also turns runtime errors and warnings into events based on your configuration.

0 commit comments

Comments
 (0)