Consider this code:
import logging print "print" logging.error("log")
I get:
print ERROR:root:log
now, if I turn on the thid-party module at the beginning of the previous code and re-run it, I only get:
print
there are some previous questions about this, but here I can not touch on the module that I import.
The code of the third-party module is here: http://atlas-sw.cern.ch/cgi-bin/viewcvs-atlas.cgi/offline/DataManagement/DQ2/dq2.clientapi/lib/dq2/clientapi/DQ2.py?view= markup , but my question is more general: regardless of the module I import, I want clean logging work as expected
Some (non-working) proposed solutions:
from dq2.clientapi.DQ2 import DQ2 import logging del logging.root.handlers[:]
from dq2.clientapi.DQ2 import DQ2 import logging logging.disable(logging.NOTSET)
logs = logging.getLogger('root') logs.error("Some error")
The following works, but produced some additional errors:
from dq2.clientapi.DQ2 import DQ2 import logging reload(logging)
I get:
print ERROR:root:log Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43- opt/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 1509, in shutdown h.close() File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 705, in close del _handlers[self] KeyError: <logging.StreamHandler instance at 0x2aea031f7248> Error in sys.exitfunc: Traceback (most recent call last): File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 1509, in shutdown h.close() File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 705, in close del _handlers[self] KeyError: <logging.StreamHandler instance at 0x2aea031f7248>
from dq2.clientapi.DQ2 import DQ2 import logging logger = logging.getLogger(__name__) ch = logging.StreamHandler() logger.addHandler(ch) logger.error("log")