Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

change to root logger affects other projects

Open PythonFZ opened this issue 3 years ago • 4 comments

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 avatar Nov 02 '21 13:11 PythonFZ

~~This seems to be fixed in 0.13.0+e571ba9~~

PythonFZ avatar Nov 05 '21 17:11 PythonFZ

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)>]

florczakraf avatar Jan 14 '22 09:01 florczakraf

Still an issue in 0.15.2:

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

ramdrop avatar Mar 12 '22 22:03 ramdrop

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

LaoYang1994 avatar Aug 22 '22 10:08 LaoYang1994

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()

ypicard avatar Nov 05 '22 16:11 ypicard

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.

Neflux avatar Jun 28 '23 09:06 Neflux