Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] init_logger may panic if called from enviroment where the logger was already initialized (e.g., PyO3) #61

Closed
gabrik opened this issue Apr 21, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@gabrik
Copy link
Contributor

gabrik commented Apr 21, 2022

Describe the bug

When the zenoh.init_logger() function is called from an environment where env_logger was already initialized it crashes with the following error:

 PyErr { type: <class 'pyo3_runtime.PanicException'>, value: PanicException('env_logger::init should not be called after logger initialized: SetLoggerError(())'),

This is well documented in the env_logger crate.

A solution is to use try_init which returns an error instead of panicking, so change this line to something like

env_logger::try_init().unwrap_or_else(|_| log::warn!("`env_logger` already initialized"));;

It will avoid crashed and print in the log that the logger was already initialized.

To reproduce

Run zenoh.init_logger() in an environment with the logger already initialized (e.g. calling it from PyO3)

System info

Not applicable

@gabrik gabrik added the bug Something isn't working label Apr 21, 2022
@p-avital
Copy link
Contributor

p-avital commented Aug 3, 2022

Fixed in api-changes branch :)

@p-avital p-avital closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

No branches or pull requests

2 participants