小编mag*_*esh的帖子

为什么在使用非静态记录器之前不会打印lazy_static slog :: Logger?

如果我取消create_log,都logLOG打印在控制台上.没有它,什么也没有打印出来.到底是怎么回事?

#[macro_use]
extern crate slog;
extern crate slog_term;
extern crate slog_async;
#[macro_use]
extern crate lazy_static;

use slog::Drain;

lazy_static! {
    static ref LOG: slog::Logger = create_log();
}

fn create_log() -> slog::Logger {
    let decorator = slog_term::TermDecorator::new().force_plain().build();
    let drain = slog_term::CompactFormat::new(decorator).build().fuse();
    let drain = slog_async::Async::new(drain).build().fuse();
    slog::Logger::root(drain, o!())
}

fn main() {
    info!(LOG, "LOG");  // NOT printed unless next line is uncommented

    // let log = create_log();     // enables printing both log and LOG
    // info!(log, "log"); …
Run Code Online (Sandbox Code Playgroud)

rust

3
推荐指数
1
解决办法
304
查看次数

标签 统计

rust ×1