-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
Importing monai modifies the python root logger leaving it with a StreamHandler for stdout. This can lead to double messages when a user instantiates their own logger.
To Reproduce
Run the following script
import logging
import monai
logger = logging.getLogger(__name__)
stderr = logging.StreamHandler()
logger.addHandler(stderr)
logger.warning('hello, world')Running this prints the 'hello, world' warning twice. The second time with date and time info:

Expected behavior
It should just print hello, world. It does this if you comment out the import monai statement.
Environment
Printing MONAI config...
MONAI version: 1.1.0
Numpy version: 1.24.1
Pytorch version: 1.13.0+cu117
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: a2ec375
MONAI file: /usr/local/lib/python3.9/site-packages/monai/init.py
Optional dependencies:
Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.
Nibabel version: 5.0.0
scikit-image version: 0.19.3
Pillow version: 9.4.0
Tensorboard version: NOT INSTALLED or UNKNOWN VERSION.
gdown version: NOT INSTALLED or UNKNOWN VERSION.
TorchVision version: NOT INSTALLED or UNKNOWN VERSION.
tqdm version: NOT INSTALLED or UNKNOWN VERSION.
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: 5.9.4
pandas version: NOT INSTALLED or UNKNOWN VERSION.
einops version: NOT INSTALLED or UNKNOWN VERSION.
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.
For details about installing the optional dependencies, please visit:
https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies
Printing system config...
System: Linux
Linux version: Debian GNU/Linux 11 (bullseye)
Platform: Linux-5.4.0-122-generic-x86_64-with-glibc2.31
Processor:
Machine: x86_64
Python version: 3.9.13
Process name: python
Command: ['python', 'monai_logger.py']
Open files: []
Num physical CPUs: 64
Num logical CPUs: 64
Num usable CPUs: 64
CPU usage (%): [8.5, 6.9, 100.0, 6.0, 10.1, 6.8, 8.5, 17.9, 6.8, 7.7, 6.8, 7.6, 7.7, 6.8, 25.6, 6.8, 6.1, 9.3, 7.8, 7.8, 8.5, 9.4, 9.4, 10.2, 8.5, 9.3, 7.6, 8.5, 9.2, 7.6, 9.4, 6.8, 8.5, 0.0, 5.1, 4.3, 0.9, 0.0, 7.0, 5.1, 0.0, 0.8, 0.0, 3.4, 0.0, 0.0, 5.1, 0.0, 0.9, 0.0, 0.0, 0.0, 1.7, 5.1, 5.1, 20.7, 0.0, 13.7, 0.9, 0.8, 7.0, 0.0, 9.5, 1.7]
CPU freq. (MHz): 3392
Load avg. in last 1, 5, 15 mins (%): [4.3, 2.9, 2.7]
Disk usage (%): 14.2
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 246.0
Available memory (GB): 229.2
Used memory (GB): 15.0
Printing GPU config...
Num GPUs: 0
Has CUDA: False
cuDNN enabled: True
cuDNN version: 8500
None