为什么" Rocket已经推出"消息记录为错误?

时间:2018-06-19 07:46:03

标签: logging rust rust-rocket

我正在启动Rocket网络服务器。该应用程序使用以下相关的板条箱:

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
log = "0.4"
fern = { version = "0.5", features = ["colored"] }
rocket = "0.3.13"
rocket_codegen = "0.3.13"
rocket_contrib = "0.3.13"

在我的代码中,我使用Fern,Chrono和Log crates设置消息的颜色,以创建漂亮的彩色消息日志。然后我启动一个标准的Rocket服务器:

#![feature(plugin)]
#![plugin(rocket_codegen)]

#[macro_use]
extern crate log;
extern crate chrono;
extern crate fern;
extern crate rocket;

use fern::colors::{Color, ColoredLevelConfig};

fn main() {
    let verbosity: u64 = 2;

    let colors = ColoredLevelConfig::new()
        .debug(Color::Magenta)
        .info(Color::Green)
        .trace(Color::BrightBlue);

    let level = match verbosity {
        0 => log::LevelFilter::Warn,
        1 => log::LevelFilter::Info,
        2 => log::LevelFilter::Debug,
        _3_or_more => log::LevelFilter::Trace,
    };

    fern::Dispatch::new()
        .chain(std::io::stdout())
        .level(level)
        .format(move |out, message, record| {
            out.finish(format_args!(
                "{} {}\t [{}] {}",
                chrono::Utc::now().format("%Y-%m-%d %H:%M:%S"),
                colors.color(record.level()),
                record.target(),
                message
            ))
        })
        .apply()
        .unwrap();

    info!("Starting up ");
    debug!("Verbosity level is {}", verbosity);

    // Startup the controller
    info!("Starting web service controller");
    rocket::ignite().mount("/", routes![index]).launch();
}

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

当我运行它时,Rocket正常启动并运行正常但它记录Rocket已启动为错误:

adrian@bastet:~/Dropbox/rust/rocket$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/rocket`
2018-06-19 07:35:31 INFO         [rocket] Starting up
2018-06-19 07:35:31 DEBUG        [rocket] Verbosity level is 2
2018-06-19 07:35:31 INFO         [rocket] Starting web service controller
2018-06-19 07:35:31 INFO         [rocket::rocket]   Configured for development.
2018-06-19 07:35:31 INFO         [_] address: localhost
2018-06-19 07:35:31 INFO         [_] port: 8000
2018-06-19 07:35:31 INFO         [_] log: normal
2018-06-19 07:35:31 INFO         [_] workers: 16
2018-06-19 07:35:31 INFO         [_] secret key: generated
2018-06-19 07:35:31 INFO         [_] limits: forms = 32KiB
2018-06-19 07:35:31 INFO         [_] tls: disabled
2018-06-19 07:35:31 INFO         [rocket::rocket]   Mounting '/':
2018-06-19 07:35:31 INFO         [_] GET /
2018-06-19 07:35:31 ERROR        [launch]   Rocket has launched from http://localhost:8000
2018-06-19 07:35:31 DEBUG        [hyper::server] threads = 16

在我的屏幕上,消息是彩色编码的。

为什么来自Rocket的消息已经开始记录为ERROR?这一切都很成功,所以说错误是错误的。

0 个答案:

没有答案