Skip to content

Commit

Permalink
feat: update logging tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Jan 6, 2025
1 parent 227e006 commit 652c6ca
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
Binary file added assets/geode_log_levels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/geode_platform_console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 50 additions & 8 deletions tutorials/logging.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
# Logging

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.
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:
* `<GD FOLDER>/geode/logs` directory on `Windows` and `MacOS`
* `Android/media/com.geode.launcher/game/geode/logs` directory on `Android`

## Log Levels
There are 4 logging levels, each being more important than the previous.

> :warning: If you want to omit `geode::` from the log call, you can use ```using namespace geode::prelude``` at the top of your file
### Error

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.

```cpp
geode::log::error("I am a grave error!");
```
### Warn
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.
```cpp
geode::log::warn("I failed to fetch this list of items, but I'll retry a few times");
```

### Info

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.

```cpp
using namespace geode;
geode::log::info("Setting up the editor adjustments");
```
log::debug("Im some debug string {}", 123);
log::info("Some information for those reading logs");
log::warn("Warning: something idk");
log::error("An error message");
### Debug
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.
```cpp
geode::log::debug("Loading sheet {}", sheetName);
geode::log::debug("Filesize: {}", filesize);
geode::log::debug("Found node: {}", node->getID());
```

## Syntax
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.
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.

![Cheatsheet showing fmtlib syntax](https://hackingcpp.com/cpp/libs/fmt.png)
*Image from [https://hackingcpp.com](https://hackingcpp.com/cpp/cheat_sheets.html)*
Expand All @@ -25,6 +55,18 @@ geode::log::debug("Hello {:>10.3f} world, [{}]", 12.4f, fmt::join(someVec, ", ")
```
## Platform console
You can easily enable the platform console by going to the settings on the Geode mod ingame.
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.
![Image showing the platform console option ingame](/assets/geode_platform_console.png)
## Log levels
> :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**.
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.
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.
You can modify your log levels ingame, through **Geode's settings**.
![Image showing the log levels option](/assets/geode_log_levels.png)

0 comments on commit 652c6ca

Please sign in to comment.