rust - 启用LogTracer会导致 panic

标签 rust

我尝试实现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/

相关文章:

logging - 如何在Rust中将自定义数据传递到日志箱的宏?

rust - 如何在类似函数的过程宏中计算类型的实例并返回它?

json - Rust 和 JSON 序列化

arrays - 在 Rust 中如何在编译时确定数组的大小?

rust - 为什么我不能返回从字符串生成的 &str 值?

iterator - 从函数返回的迭代器的生存期要求冲突

rust - 错误[E0502] : cannot borrow `char_array` as mutable because it is also borrowed as immutable

rust - 为了向下转换一个特征对象,为什么它必须是静态的?

rust - 带有使用rust 的exec “tail -f xxx”

dynamic - 是否可以将特征对象转换为另一个特征对象?