isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.49k stars 2.31k forks source link

change to root logger affects other projects #4228

Open PythonFZ opened 3 years ago

PythonFZ commented 3 years ago

Describe the bug Open3D append to the Python root logger which in return yields doubled log messages when setting a logging handler in another project.

To Reproduce Steps to reproduce the behavior:

import logging
print(logging.getLogger().handlers) # > []
import opend3d
print(logging.getLogger().handlers) # > [<StreamHandler stderr (NOTSET)>]

Expected behavior Open3D should use logging.getLogger(__name__) and only change the open3D logger and not others. This should give

print(logging.getLogger(__name__).handlers) # > [<StreamHandler stderr (NOTSET)>]

where __name__ == "open3d"

PythonFZ commented 3 years ago

This seems to be fixed in 0.13.0+e571ba9

florczakraf commented 2 years ago

This is still an issue in 0.14.1

>>> import logging; print(logging.getLogger().handlers)
[]
>>> import open3d; open3d.__version__
'0.14.1'
>>> print(logging.getLogger().handlers)
[<StreamHandler <stderr> (NOTSET)>]
ramdrop commented 2 years ago

Still an issue in 0.15.2:

import logging
print(logging.getLogger().handlers) # > []
import opend3d
print(logging.getLogger().handlers) # > [<StreamHandler stderr (NOTSET)>]
LaoYang1994 commented 2 years ago

When can this problem be solved? I have the same problem.

ypicard commented 2 years ago

Breaking our logging system too. This is somewhat critical for us. Would you accept a pull request? For now, fixing locally with:

import open3d

# required because open3d changes default logging behavior (https://github.com/isl-org/Open3D/issues/4228)
logging.getLogger().handlers.clear()
Neflux commented 1 year ago

I've just encountered the same issue. While it can be resolved with a logging.root.handlers.clear(), it does raise questions. I'm curious whether this is considered bad practice on the side of Open3D. It's surprising that this could have been overlooked.