2

I am having trouble with a module (specifically pymel.core in maya) which seems to change the default logging level. When I import pymel, all the different loggers in the modules I'm using suddenly get set to debug and start spewing out loads of things that I don't want to see. It looks to me like pymel is changing the default logging level in the logging module, but I'm not quite sure where. I've looked at the logging docs and I'm not sure how to set it back to what it was before, I can only see how to set the level on an individual logger.

Can anyone suggest how I can switch the default logging level?

>>> import logging
>>> logging.getLogger().getEffectiveLevel()
30
>>> import pymel.core
>>> logging.getLogger().getEffectiveLevel()
0

I'd like to be able to set that default level back to 30 somehow, so all my loggers are back to how they were before when they inherit there level from the logging module's default. Apologies if I'm misunderstanding how the logging module works, I'm quite new to it.

ninhenzo64
  • 702
  • 1
  • 9
  • 23
  • `logging.getLogger().setLevel(logging.WARNING)`? Anyway it seems like that package is doing something wrong with their logging configuration. – Bakuriu Oct 10 '16 at 16:58
  • You can reset the logger level after import pymel via `logging.getLogger().level = logging.WARNING`. Note that there's an open [pull request](https://github.com/LumaPictures/pymel/pull/377) for a fix, you might want to ask for it to be merged. – MisterMiyagi Oct 10 '16 at 17:01

3 Answers3

3

I don't know pymel specifically but it doesn't look like it's well-behaved with respect to logging. You could try:

if __name__ == '__main__':
    import logging, pymel.core
    logging.getLogger().setLevel(logging.WARNING)  # or whatever
    logging.getLogger('pymel').setLevel(logging.WARNING)

However, this may not prevent all undesired messages from being output. You can tweak the above to adjust to what you find in practice.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
0

There's a file called pymel.conf in the Maya install in the pymel subfolder of the site-packages directory. It controls the log settings for different parts of pymel using the same config file system in the default logging module.

theodox
  • 12,028
  • 3
  • 23
  • 36
-2

I was in the similar situation like yours ,
I tried to search a lot in internet as well programatically ,
In this situation better dont use import logging , Use a simple function call like this. ,
def own_log(msg): with open ("test.log",'a') as fd: fd.write(msg)
I suggested this because its simple and logging module setslevel globaly .

EDIT:
Maybe u should use best some best practices, try this logging.getLogger(__name__)

yunus
  • 2,445
  • 1
  • 14
  • 12