Crate godot_logger

source ·
Expand description

A simple logger that prints to Godot’s output window

godot-logger is a simple logger that prints log messages to the output console inside the Godot game engine. It is built around the logging facade of the log crate, and uses the godot_print! macro from the gdnative bindings.

It is possible to configure different log levels for different Rust modules, similar to other popular logging frameworks such as env_logger or log4rs. Simply provide a list as the second argument to the init function with module names and log levels.

Use

Add godot-logger and log as dependencies to Cargo.toml.

Then initialize godot-logger in the init function that is exported by gdnative. Pass in a default log level, and a list with module-level overrides (can be empty).

use gdnative::prelude::*;
use godot_logger::GodotLogger;
use log::{Level, LevelFilter};

fn init(handle: InitHandle) {
    GodotLogger::builder()
        .default_log_level(Level::Info)
        .add_filter("godot_logger", LevelFilter::Debug)
        .init();
    log::debug!("Initialized the logger");
}

godot_init!(init);

The following will appear in the Output console inside Godot:

2021-09-25 19:29:25 DEBUG godot_logger Initialized the logger

Structs

A Builder that configures and initializes the Godot logger
A logger that prints to the output console of the Godot game engine