Log crate isn't working

I have a tiny crate with the following Cargo.toml:

[package]
name = "logger"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "*"

and the following main.rs code:

use log::{info, trace};

fn main() {
    info!("hi");
    trace!("hi");
}

I tried this code on release mode on two toolchains.

rustc --version --verbose:

rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: i686-pc-windows-msvc
release: 1.74.1
LLVM version: 17.0.4

rustc --version --verbose:

rustc 1.76.0-nightly (90e321d82 2023-12-02)
binary: rustc
commit-hash: 90e321d82a0a9c3d0e3f180d4d17541b729072e0
commit-date: 2023-12-02
host: i686-pc-windows-msvc
release: 1.76.0-nightly
LLVM version: 17.0.5

but ends up doing nothing and I don't know what's wrong.

I always recommend reading the documentation for crates you add: log - Rust

If no logging implementation is selected, the facade falls back to a “noop” implementation that ignores all log messages

5 Likes

Thanks for pointing it out,but how do I select an implementation then?

There's a whole list here log - Rust
If you don't know what you need just go with the first one for now.

1 Like

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.