[all-commits] [llvm/llvm-project] 35d26b: Don't use root logger at import time

Stella Laurenzo via All-commits all-commits at lists.llvm.org
Mon Dec 5 17:56:32 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 35d26be21976ce1a63f24d41c969996776ee16bf
      https://github.com/llvm/llvm-project/commit/35d26be21976ce1a63f24d41c969996776ee16bf
  Author: Stella Laurenzo <laurenzo at google.com>
  Date:   2022-12-05 (Mon, 05 Dec 2022)

  Changed paths:
    M mlir/python/mlir/_mlir_libs/__init__.py

  Log Message:
  -----------
  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




More information about the All-commits mailing list