Make rust use the 'crates.io' version of 'log'


#1

For my Rust project I want to use the log logging library (together with env_logger of course).

In my Cargo.toml, I have

[dependencies]
log="*"

and then in my main Rust file, I refer to the crate with

extern crate log;

But somehow, my compiler thinks, I’m using the compiler’s log crate and complains:

src/main.rs:11:1: 11:18 warning: use of unstable library feature 'rustc_private': use the crates.io `log` library instead
src/main.rs:11 extern crate log;

src/main.rs:11:1: 11:18 help: add #![feature(rustc_private)] to the crate attributes to silence this warning
src/main.rs:11 extern crate log;

How do I get cargo/rust to use the crates.io version of log (it gets built when I run cargo build)?
It may be that my rust installation is borked up (been using rustup.sh for months). If so, how would I fix this? (I already tried rustup.sh --uninstall, didn’t help :frowning: )


#2

That’s a little odd… could you post your project? For me, the following setup (built with cargo build works:

Cargo.toml

[package]

name = "test-logger"
version = "0.0.1"
authors = ["..."]

[dependencies]
log = "*"
env_logger = "*"

src/main.rs:

#[macro_use]
extern crate log;
extern crate env_logger;

fn main() {
    env_logger::init().unwrap();
    info!("Hello, world!");
}

Is yours different?


#3

Very odd indeed. Your example works perfectly on my installation whereas my project gives me warnings or fails to build.

I have created a minimal example Gist.

I have found a way to compile my program. Apparently, the order of extern crate statements matters?!
When I move extern crate log above extern crate docopt_macros, it compiles. If log comes after docopt_macros, it fails.

Is that intentional? Feels a bit fragile to me.

#![feature(plugin)] 

// works, if you move the `extern crate log` here 
#[plugin]
extern crate docopt_macros;

#[macro_use]
extern crate log;
extern crate env_logger;

#4

That seems like a bug (probably related to compiler plugins). Report it.