LumaPictures / pymel

Python in Maya Done Right
Other
490 stars 131 forks source link

Incompatible with logging.addLevelName #438

Open mottosso opened 3 years ago

mottosso commented 3 years ago

Hi all,

To make levelname more pleasant, a user can override the default e.g. INFO and WARNING labels with something else, such as..

import logging

log = logging.getLogger("myLogger")
fmt = logging.Formatter("%(levelname)s : %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(fmt)
log.addHandler(handler)
log.propagate = False

log.info("Hello!")
# INFO : Hello!

logging.addLevelName(logging.INFO, "Info")
log.info("Hello!")
# Info : Hello!

However, this breaks PyMEL. :(

# Error: root : Uncaught exception:
Traceback (most recent call last):
  File "<maya console>", line 2, in <module>
  File "/opt/autodesk/maya-2019.2/lib/python2.7/site-packages/pymel/core/init.py", line 13, in <module>
    import pymel.internal.factories as _factories
  File "/opt/autodesk/maya-2019.2/lib/python2.7/site-packages/pymel/internal/factories.py", line 27, in <module>
    from . import apicache
  File "/opt/autodesk/maya-2019.2/lib/python2.7/site-packages/pymel/internal/apicache.py", line 13, in <module>
    from pymel.api.plugins import mpxNamesToApiEnumNames
  File "/opt/autodesk/maya-2019.2/lib/python2.7/site-packages/pymel/api/plugins.py", line 319, in <module>
    _logger.raiseLog(_logger.WARNING, 'found new MPx classes: %s. Run pymel.api.plugins._suggestNewMPxValues()'
AttributeError: 'Logger' object has no attribute 'WARNING' # 
# Error: AttributeError: 'Logger' object has no attribute 'WARNING' #

Because of this here.

https://github.com/LumaPictures/pymel/blob/a2dc935f2be319ac65e213eebcfb69f72a05ba08/pymel/internal/plogging.py#L216-L219

Would recommend explicitly storing the exact labels, since they are assumed elsewhere. For example..

logger.INFO = logging.INFO
logger.WARNING = logging.WARNING
logger.CRITICAL = logging.CRITICAL

Or better yet, use the original values to avoid confusion.