Skip to content

Logging

Darkly77 edited this page Jun 21, 2023 · 9 revisions

Logging is a native Godot feature. Logs are displayed in the editor's console, and saved to the godot.log file.

To log data to Godot's log, use ModLoaderLog.{method}. See ModLoaderLog for a list of available methods.

Log Files

Logging is done in two places by ModLoader. Replace GAMENAME with the program's name.

Location Name Description
%appdata%/GAMENAME/logs/godot.log godot.log Godot's native log file
%appdata%/GAMENAME/mods.log mods.log Custom file created by ModLoader.
Has timestamps and excludes print logs

For example, Brotato's logs are here:

  • %appdata%/Brotato/logs/godot.log
  • %appdata%/Brotato/mods.log

Verbosity

ModLoader only logs errors by default, so logging for other levels of verbosity needs to be enabled with CLI args.

Each level of verbosity includes the previous levels (eg. logging DEBUG will also log INFO and WARNING)

Enabling a lower verbosity logging level will enable all logging for the level(s) above it.

Arg Level
na Error (always enabled)
-v or --log-warning Warning
-vv or --log-info Info
-vvv or --log-debug Debug

Ignoring logs

You can ignore logs from a specific log name by using the --log-ignore flag.
For multiple names, list them separated by commas. Do not use spaces after each comma.

--log-ignore=ModLoader,ModLoader:ModData

Methods

All methods take the form of ModLoaderUtils.METHOD, eg. ModLoaderUtils.log_info.

Method Level Prefix Description
ModLoaderUtils.log_fatal Error FATAL-ERROR Logs the error in red and a stack trace.
Stops the execution in editor
ModLoaderUtils.log_error Error ERROR Logs the message. Pushes an error
ModLoaderUtils.log_warning Warning WARNING Logs the message. Pushes a warning
ModLoaderUtils.log_info Info INFO Logs the message
ModLoaderUtils.log_success Info SUCCESS Logs the message
ModLoaderUtils.log_debug Debug DEBUG Logs the message
ModLoaderUtils.log_debug_json_print Debug DEBUG Logs the message. Logs the 2nd arg JSON.print

All methods take arguments like this:

ModLoaderUtils.METHOD(message: String, mod_name: String)

The only exception is log_debug_json_print, which takes arguments like this, where json_printable is an object that can be printed as JSON:

ModLoaderUtils.log_debug_json_print(message: String, json_printable, mod_name: String)

Editor

When running in the editor, ModLoader always logs everything (ie. up to the "DEBUG" level).

ModLoader also uses assert in a few places, eg. when validating that your mods have the correct files in the right places. This will trigger a fatal error if the validation fails, and the error will be shown in the editor console. This may seem inconvenient, but it's a great way to get immediate feedback when you mod is, for example, missing a mandatory file, without needing to identify and debug the issue yourself.

Fatal crashes triggered by assert will only happen in the editor. If you're testing/playing mods outside of it, the game will continue running as usual.