Env_logger within dylib of hot-lib-reloader doesn't work

Hello. I'm developing an egui application with hot-lib-reloader. The structure of the app is the same as egui example. In the app I use env_logger for logging. If you're too lazy to check out the example the setup is something like this.
src/main.rs:

#[cfg(feature = "reload")]
use hot_lib::*;
#[cfg(not(feature = "reload"))]
use lib::*;

#[cfg(feature = "reload")]
#[hot_lib_reloader::hot_module(dylib = "lib")]
mod hot_lib {
    pub use lib::State;
    // the function `render` from this file is hot-reloaded for
    // `update` function of `eframe::App` 
    hot_functions_from_file!("lib/src/lib.rs");

    #[lib_change_subscription]
    pub fn subscribe() -> hot_lib_reloader::LibReloadObserver {}
}
fn main() -> eframe::Result<()> {
    env_logger::init();
    log::info!("hello") // this works
    // egui/eframe stuff
}

However, within the lib/src/lib.rs if I have any log::error! calls, it doesn't get printed out when ran with RUST_LOG=debug cargo run --features reload (dynamically), and it does get printed out when ran with RUST_LOG=debug cargo run (statically).

The result of following within --features reload

println!("{:?}", env::var("RUST_LOG"));
println!("{:?}", log::log_enabled!(log::Level::Debug));

Is

Ok("debug")
false

This is very strange, what is the reason the logging doesn't get enabled within dynamic library?

RUST_LOG need to be set as your program's name or the level of the log

check out the document

A simple way, to enable log is to set RUST_LOG as trace

I don't know the details of the hot-lib-reloader library, but I would guess probably the module path had been messed up. log use the module name as default log target. quote from document for log:

A target is a string which defaults to the module path of the location of the log request, though that default may be overridden. Logger implementations typically use the target to filter requests based on some user configuration.

you can do some experiments with explicit target attribute (the following snippet is just for demonstration, I don't know exactly how the hot-lib-realoder is implemented, do your own research):

println!("{:?}", log::log_enabled!(target: "lib", log::Level::Debug));
println!("{:?}", log::log_enabled!(target: "hot_lib", log::Level::Debug));
println!("{:?}", log::log_enabled!(target: "hot_lib::lib", log::Level::Debug));

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.