Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with logging.addLevelName #438

Open
mottosso opened this issue Jan 27, 2021 · 0 comments
Open

Incompatible with logging.addLevelName #438

mottosso opened this issue Jan 27, 2021 · 0 comments

Comments

@mottosso
Copy link

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.

# for convenience, stick 'DEBUG', 'INFO', 'WARNING', etc attributes onto
# the logger itself
for logEnumValue in logLevels.values():
setattr(logger, logEnumValue.key, logEnumValue.index)

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.

mottosso added a commit to ragdolldynamics/ragdoll-maya that referenced this issue Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant