python logging and maya

807 views
Skip to first unread message

sberger

unread,
Oct 9, 2009, 10:18:20 AM10/9/09
to python_inside_maya
Hi, I have been experimenting with the python logging module... for
some reason the debug and info level of the logging are not printed in
Maya..

Here is a simple example:
import logging
def go():
logging.basicConfig(level=logging.DEBUG)

logger1 = logging.getLogger('package1.module1')

logger1.debug('This is a debug message')
logger1.info('This is an info message')
logger1.warning('This is a warning message')
logger1.error('This is an error message')
logger1.critical('This is a critical error message')

go()

When executed in Maya I get this result:
# WARNING:package1.module1:This is a warning message
# ERROR:package1.module1:This is an error message
# CRITICAL:package1.module1:This is a critical error message

Where it should be:
DEBUG:package1.module1:This is a debug message
INFO:package1.module1:This is an info message
WARNING:package1.module1:This is a warning message
ERROR:package1.module1:This is an error message
CRITICAL:package1.module1:This is a critical error message


Anyone have any idea why that is?

Sylvain Berger

unread,
Oct 9, 2009, 10:45:12 AM10/9/09
to python_inside_maya
Finally I am not too sure how this works... I can get the debug message to log sometimes... not too sure why yet.  There is something in the logging concept that I am not getting.
--
"A pit would not be complete without a Freeman coming out of it."
The Vortigaunt

Ofer Koren

unread,
Oct 9, 2009, 12:05:26 PM10/9/09
to python_in...@googlegroups.com

logging.basicConfig is only run ONCE for the python session. It's an application-level initialization of the logging module, so it shouldn't be run more than once. After that, you'll need to change the log-level via the loggers:

 

logger.setLevel(logging.DEBUG)

 

or via the streams attached to those loggers:

 

for handler in logger.handlers:

                handler.setLevel(logging.DEBUG)

 

 

pymel 0.9 uses and initializes the logging module, and allows user-customization throught the pymel.conf file.

Also check out the Logging-Menu, which allow the logging module to be administered through the UI:

 

import pymel.tools.loggingControl as loggingControl

loggingControl.initMenu()

Sylvain Berger

unread,
Oct 9, 2009, 1:48:35 PM10/9/09
to python_in...@googlegroups.com
ho cool, I will look into that. Thanks for the explanation on the logging.basicConfig.
Reply all
Reply to author
Forward
0 new messages