Don't use root logger at import time
authorStella Laurenzo <laurenzo@google.com>
Tue, 6 Dec 2022 01:42:38 +0000 (17:42 -0800)
committerStella Laurenzo <laurenzo@google.com>
Tue, 6 Dec 2022 01:42:38 +0000 (17:42 -0800)
commit35d26be21976ce1a63f24d41c969996776ee16bf
tree7f087f476e555a24589446b3441dd3f2c2027a85
parent571abdefd174c1cd8883c5307e70d365184d6b83
Don't use root logger at import time

At import time, these calls to `logging.debug()` implicitly call `logging.basicConfig` (https://docs.python.org/3/library/logging.html#logging.basicConfig), setting logging config for the whole project which cannot then be overwritten later. For instance, consider the following test script:

```
import logging
import jax

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
logger.info('info')
```
This should log out `'info'`, but because when `import jax` is called, this `_mlir_lib/__init__.py` file is run and a `logging.debug` is called, calling `logging.basicConfig`, my `logging.basicConfig(level=logging.INFO)` does nothing.

Fix: instead of using root logger, use a module level logger.

Found in this issue: https://github.com/google/jax/issues/12526

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D134812
mlir/python/mlir/_mlir_libs/__init__.py