daboross / fern

Simple, efficient logging for Rust
MIT License
848 stars 51 forks source link

Unresolved import `fern::colors` #71

Closed lyuben-todorov closed 4 years ago

lyuben-todorov commented 4 years ago

I'm trying to use fern with one of the examples in the repo:

// ...
extern crate log;
extern crate fern;
// ...
use fern::colors::{Color, ColoredLevelConfig};
use log::{debug, error, info, trace, warn};

fn main() {
    setup_logger();
//...
}
fn setup_logger() {
    let colors_line = ColoredLevelConfig::new()
        .error(Color::Red)
        .warn(Color::Yellow)
        .info(Color::White)
        .debug(Color::White)
        .trace(Color::BrightBlack);

    let colors_level = colors_line.clone().info(Color::Green);
    fern::Dispatch::new()
        .format(move |out, message, record| {
            out.finish(format_args!(
                "{color_line}[{date}][{target}][{level}{color_line}] {message}\x1B[0m",
                color_line = format_args!(
                    "\x1B[{}m",
                    colors_line.get_color(&record.level()).to_fg_str()
                ),
                date = chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
                target = record.target(),
                level = colors_level.color(record.level()),
                message = message,
            ));
        })
        .level(log::LevelFilter::Warn)
        .level_for("pretty_colored", log::LevelFilter::Trace)
        .chain(std::io::stdout())
        .apply()
        .unwrap();

    debug!("finished setting up logging! yay!");
}

This is the output of cargo build:

   Compiling piko v0.1.0 (/home/lyubentodorov/Projects/piko)
error[E0432]: unresolved import `fern::colors`
  --> src/bin/main.rs:33:11
   |
33 | use fern::colors::{Color, ColoredLevelConfig};
   |           ^^^^^^ could not find `colors` in `fern`

warning: unused imports: `error`, `trace`, `warn`
  --> src/bin/main.rs:34:18
   |
34 | use log::{debug, error, info, trace, warn};
   |                  ^^^^^        ^^^^^  ^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0432`.
error: could not compile `piko`.

To learn more, run the command again with --verbose.

And these are my dependancies:

[dependencies]
rand = "0.7.3"
config = "0.10.1"
rayon = "1.3.1"
sha2 = "0.9.1"
byteorder = "1.3.4"
bytes = "0.5.6"
num = "0.3.0"
num-traits = "0.2.12"
num-derive = "0.3.1"
serde = { version = "1.0.115", features = ["derive"] }
serde_cbor = "0.11.1"
clokwerk = "0.3.3"
lazy_static = "1.4.0"
log = "0.4"
fern = "0.5"
chrono = "0.4.15"

I've tried with a couple of versions of log and fern, including the latest ones. I can't see what I'm doing wrong and I couldn't find similar issues anywhere.

lyuben-todorov commented 4 years ago

So much for looking,

[dependencies]
fern = { version = "0.6.0", features = ["colored"] }

I'm sorry, closing.