gamedig / rust-gamedig

Game Server Query Library.
https://crates.io/crates/gamedig
MIT License
35 stars 10 forks source link

Add debug logging #188

Open CosminPerRam opened 4 months ago

CosminPerRam commented 4 months ago

What is this feature about? Debug logs are very useful in examining behavior in all kinds of possible use cases. This helps in eventual user-encountered bugs.

Additional context/references Add debug logging like in the Node version: image (just a simple example of logging something)

The log crate would be perfect for this, I don't know any better alternatives.

cainthebest commented 4 months ago

Is this for just debug logging as we could just add a cfg assertion and print it.

cainthebest commented 4 months ago

eg

fn debug_print<T: std::fmt::Debug>(msg: T) {
    if cfg!(debug_assertions) {
        println!("{:?}", msg);
    }
}

fn main() {
    debug_print("This will only be printed in debug mode");
}
Douile commented 4 months ago

the log crate would be perfect for this

There's also tracing but that is a lot more complex.

CosminPerRam commented 4 months ago

eg

I wouldn't use something like this as the user couldn't control this with their log facade. Many libraries already use the log create for debug and stuff.