was recently exploring the use of env_logger
library in Rust, it’s a great library. I encountered, however, an issue that is related to a multithreaded scenario, where, if the logger is already initialized, the thread panics as it cannot re-initialize it. I’m getting this error
thread '<unnamed>' panicked at 'Builder::init should not be called after logger initialized: SetLoggerError(())', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/env_logger-0.10.0/src/lib.rs:816:14
The question is straight-forward – how does one check if logger is already initialized, and proceed with Builder::init only in that case (so that a thread does not panic)?
>Solution :
Call Builder::try_init()
instead. It returns an error instead of panicking.