Skip to content

Commit 652c6ca

Browse files
committed
feat: update logging tutorial
1 parent 227e006 commit 652c6ca

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

Diff for: assets/geode_log_levels.png

520 KB
Loading

Diff for: assets/geode_platform_console.png

407 KB
Loading

Diff for: tutorials/logging.md

+50-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
# Logging
22

3-
Geode provides a builtin logger with [fmtlib](https://fmt.dev/latest/index.html) formatting, which you can view in real time via the [platform console](#platform-console), or later on by checking the logs in the `geode/logs/` folder.
3+
Geode provides a builtin logger with [fmtlib](https://fmt.dev/latest/index.html) formatting, which you can view in real time via the [platform console](#platform-console), or later on by checking the logs in the:
4+
* `<GD FOLDER>/geode/logs` directory on `Windows` and `MacOS`
5+
* `Android/media/com.geode.launcher/game/geode/logs` directory on `Android`
46

57
## Log Levels
68
There are 4 logging levels, each being more important than the previous.
9+
10+
> :warning: If you want to omit `geode::` from the log call, you can use ```using namespace geode::prelude``` at the top of your file
11+
12+
### Error
13+
14+
This is the highest priority level, used for logging errors that interrupt your mod's functionality, **without recovery**. As examples, the following cases apply: an API call failing, not finding a node in a specific layer that you need, etc. Use this level sparingly.
15+
16+
```cpp
17+
geode::log::error("I am a grave error!");
18+
```
19+
20+
### Warn
21+
22+
This level is used for warning about certain aspects of your mod that failed, but aren't critical to its functionality / can be recovered from. For example, an API request failing (**but the mod retries the connection**), some non-vital setting or saved value not being set that you have a default for, etc.
23+
24+
```cpp
25+
geode::log::warn("I failed to fetch this list of items, but I'll retry a few times");
26+
```
27+
28+
### Info
29+
30+
This level is used for logging information about what your mod is doing. You shouldn't use this level to spam info messages, just simple information. For example, messages like **"Loading assets for scene"** are suitable, but **"Coordinates: {120.3, 150.3}"** being spammed over and over should be set to the lowest logging level.
31+
732
```cpp
8-
using namespace geode;
33+
geode::log::info("Setting up the editor adjustments");
34+
```
935
10-
log::debug("Im some debug string {}", 123);
11-
log::info("Some information for those reading logs");
12-
log::warn("Warning: something idk");
13-
log::error("An error message");
36+
### Debug
37+
38+
Use this level for anything you find useful to log! May that be values used in your mod, more specific text, and going into more detail than the info level. For example, while for `info` we logged something like **"Loading assets for scene"**, for `debug` we can log **"Loading spritesheet MyModSheet.png"** or the coordinates message from above.
39+
40+
```cpp
41+
geode::log::debug("Loading sheet {}", sheetName);
42+
geode::log::debug("Filesize: {}", filesize);
43+
geode::log::debug("Found node: {}", node->getID());
1444
```
1545

1646
## Syntax
17-
The syntax for formatting logs is the same as [fmtlib](https://fmt.dev/latest/syntax.html). Geode itself provides formatters for a few common types, such as `CCPoint`, `CCNode*`, etc.
47+
The logger uses [fmtlib](https://fmt.dev/latest/syntax.html) under the hood, which means you can use its syntax, which will get forwarded to fmtlib. Geode also provides formatters for a few common types, such as `CCPoint`, `CCNode`, etc.
1848

1949
![Cheatsheet showing fmtlib syntax](https://hackingcpp.com/cpp/libs/fmt.png)
2050
*Image from [https://hackingcpp.com](https://hackingcpp.com/cpp/cheat_sheets.html)*
@@ -25,6 +55,18 @@ geode::log::debug("Hello {:>10.3f} world, [{}]", 12.4f, fmt::join(someVec, ", ")
2555
```
2656
2757
## Platform console
28-
You can easily enable the platform console by going to the settings on the Geode mod ingame.
58+
The platform console is the quickest way to see the logs, running real time ingame. You can open the platform console by going to the Geode settings.
2959
3060
![Image showing the platform console option ingame](/assets/geode_platform_console.png)
61+
62+
## Log levels
63+
64+
> :warning: As of the time of the last documentation update, log levels are **still being worked on**, and will be soon released in **a future Geode update**.
65+
66+
Log levels are a system that hide the less important logs from the **platform console** and the **log files generated by Geode**. The log level can be customized individually for both of these output locations, so you can have a log level of **info** for the log files, and a log level of **debug** for the platform console.
67+
68+
The log level takes the value **debug**, **info**, **warn** or **error**. Setting the log level to one of those values will only allow logs with that level **or higher** to be written. For example, log level **warn** will only show **warns** and **errors**, while log level **info** will show **info**, **warn** and **error** logs. The default values of those log levels is **info** for both channels.
69+
70+
You can modify your log levels ingame, through **Geode's settings**.
71+
72+
![Image showing the log levels option](/assets/geode_log_levels.png)

0 commit comments

Comments
 (0)