Introduction
In the last part, we went over the basic setup for qtmetaobject-rs. In this post, we will set up the basic logging stuff for qt. While logging is not flashy or the best way to debug, it seriously sucks to work without it.
Initialize Logging
- We first need to add log and env_logger as dependencies in
Cargo.toml
. - Initilaize logger in
main.rs
.
fn main() {
qmetaobject::log::init_qt_to_rust();
env_logger::init();
info!("Log⋅Test");
// Everythin Else
}
- Run project
RUST_LOG=warn,error,info,debug,trace cargo run
Note: Logging from both Rust and QML side (console.log()) should now work.
Autoload variable
While this works, it would be preferable not to set RUST_LOG every time for the project. I decided to use direnv to set the RUST_LOG variable for the directory rather than a global variable. The instructions are given below:
Install direnv
The install instructions for different distros can be found here. Since I am using arch, I decided to install it from AUR.
Hook into Shell
direnv works with many shells. Instructions to each shell can be found here.
Create .envrc
file
We need to create .envrc
file in the root of the project with the following contents:
export RUST_LOG=error,warn,info,debug,trace
direnv should ask us to allow the .envrc
file the first time we cd to the project directory. Then the RUST_LOG variable should automatically be set and unset when entering and leaving the project, respectively.
Conclusion
The following post will be about using KI18n with qmetaobject-rs, which is a KDE localization framework.
Top comments (0)