我尝试实现this actix tracing_log logging solution导致 panic
thread 'main' panicked at 'Failed to set logger: SetLoggerError(())', mytool/src/main.rs:112:23
stack backtrace:
0: rust_begin_unwind
at /rustc/18bf6b4f01a6feaf7259b/library/std/src/panicking.rs:475
1: core::panicking::panic_fmt
at /rustc/18bf6b4f01a6feaf7259b/library/core/src/panicking.rs:85
2: core::option::expect_none_failed
at /rustc/18bf6b4f01a6feaf7259b/library/core/src/option.rs:1221
3: mytool::main::{{closure}}
4: std::thread::local::LocalKey<T>::with
5: tokio::macros::scoped_tls::ScopedKey<T>::set
6: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
7: std::thread::local::LocalKey<T>::with
8: tokio::macros::scoped_tls::ScopedKey<T>::set
9: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on
10: tokio::runtime::context::enter
11: tokio::runtime::handle::Handle::enter
12: actix_rt::builder::SystemRunner::block_on
13: mytool::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic in Arbiter thread.
backtrace的含义尚不明确-如何弄清楚为什么会出现 panic ?
最佳答案
this article提到LogTracer::init()
应该首先在main中完成。这样做会导致随后的 panic
thread 'main' panicked at 'Builder::init should not be called after logger initialized: SetLoggerError(())', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/env_logger-0.6.2/src/lib.rs:715:25
stack backtrace:
...
显然有一个进一步向下初始化的env_logger,它干扰了LogTracer删除env_logger可以解决此问题。
关于rust - 启用LogTracer会导致 panic ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66115372/