You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/recipes/logging.md
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,18 +25,16 @@ macro_rules! console_print {
25
25
26
26
A more robust solution is to integrate an existing logging library.
27
27
28
-
This recipe demonstrates using the log crate with flexi-logger. While most of this guide will work with other backends, the initialization and `LogWriter` implementation may differ.
28
+
This recipe demonstrates using the `log` crate with `flexi-logger`. While most of this guide will work with other backends, the initialization and `LogWriter` implementation may differ.
29
29
30
-
First add the following crates to your `Cargo.toml` file.
30
+
First add the following crates to your `Cargo.toml` file. You may want to check the crates.io pages of the crates for any updates.
31
31
32
32
```toml
33
33
log = "0.4.14"
34
34
flexi_logger = "0.17.1"
35
35
```
36
36
37
-
As the logger will need to use Godot's logging methods, add a Writer implementation:
38
-
39
-
When using flexi_logger it requires a LogWriter implementation that can point to the godot_print! macro. Note: this will vary by logging framework.
37
+
Then, write some code that glues the logging crates with Godot's logging interface. `flexi-logger`, for example, requires a `LogWriter` implementation:
After adding the above class with the `handle.add_class::<DebugLogger>()` in the `init(handle: InitHandle)` function, add it as an Autoload Singleton in your project and you can access the logging functionality with the following function.
163
-
164
-
In the example below, I chose the name "game_logger" for the Autoload singleton.
160
+
After adding the class above with `handle.add_class::<DebugLogger>()` in the `init` function, you may add it as an Autoload Singleton in your project for easy access. In the example below, the name "game_logger" is chosen for the Autoload singleton:
165
161
166
162
```gdscript
167
163
game_logger.trace("name_of_script.gd", "this is a trace message")
0 commit comments