Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

env_logger initialized only once?

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)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Call Builder::try_init() instead. It returns an error instead of panicking.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading