Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for godot4 #79

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ categories = [
[dependencies]
anyhow = "1"
chrono = ">= 0.4"
gdnative-core = ">= 0.9"
log = ">= 0.4"
log4rs = "1"

[dependencies.gdnative-core]
version = ">= 0.9"
optional = true

[dependencies.godot]
git = "https://github.com/godot-rust/gdext"
branch = "master"
optional = true

[dev-dependencies]
gdnative = ">= 0.9"

[features]
default = ["godot3"]
godot3 = ["gdnative-core"]
godot4 = ["godot"]
3 changes: 3 additions & 0 deletions src/appender.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use chrono::Local;
#[cfg(feature = "godot3")]
use gdnative_core::{godot_print, godot_warn};
#[cfg(feature = "godot4")]
use godot::log::{godot_print, godot_warn};
use log::{Level, Record};
use log4rs::append::Append;

Expand Down
36 changes: 35 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! [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.
//! [`godot_print!`] macro from the [gdnative] or [gdext] 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
Expand All @@ -12,6 +12,10 @@
//!
//! Add [godot-logger] and [log] as dependencies to `Cargo.toml`.
//!
//! Enable the feature `godot3` or `godot4` according to your godot version.
//!
//! ## godot3
//!
//! 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).
//!
Expand All @@ -31,6 +35,29 @@
//! godot_init!(init);
//! ```
//!
//! ## godot4
//!
//! ```ignore
//! use godot::prelude::*;
//! use godot_logger::GodotLogger;
//! use log::{Level, LevelFilter};
//!
//! struct MyExtension;
//!
//! #[gdextension]
//! unsafe impl ExtensionLibrary for MyExtension {
//! fn on_level_init(level: InitLevel) {
//! if level == InitLevel::Core {
//! GodotLogger::builder()
//! .default_log_level(Level::Info)
//! .add_filter("godot_logger", LevelFilter::Debug)
//! .init();
//! log::debug!("Initialized the logger");
//! }
//! }
//! }
//! ```
//!
//! The following will appear in the _Output_ console inside Godot:
//!
//! ```text
Expand All @@ -39,12 +66,19 @@
//!
//! [env_logger]: https://crates.io/crates/env_logger
//! [gdnative]: https://crates.io/crates/gdnative
//! [gdext]: https://github.com/godot-rust/gdext
//! [godot-logger]: https://crates.io/crates/godot-logger
//! [`godot_print!`]: https://docs.rs/gdnative/latest/gdnative/macro.godot_print.html
//! [log]: https://crates.io/crates/log
//! [log4rs]: https://crates.io/crates/log4rs
//! [Godot]: https://godotengine.org/

#[cfg(all(not(feature = "godot3"), not(feature = "godot4")))]
compile_error!("You need to enable godot3 or godot4 feature");

#[cfg(all(feature = "godot3", feature = "godot4"))]
compile_error!("You need to enable godot3 or godot4 feature");

pub use crate::builder::*;

mod appender;
Expand Down
Loading