Hi guys, I have setup this logging setup in the __init__.py file of
my mfxMaya package
# setup logging
import logging
import maya.OpenMaya as OpenMaya
MAYA_LOGGING_SETUP = False
class MayaLogHandler(logging.Handler):
def emit(self, record):
if record.levelno > logging.ERROR:
# Critical
OpenMaya.MGlobal.displayError(record.getMessage())
elif record.levelno > logging.WARNING:
# error
OpenMaya.MGlobal.displayError(record.getMessage())
elif record.levelno > logging.INFO:
# warning
OpenMaya.MGlobal.displayWarning(record.getMessage())
elif record.levelno <= logging.DEBUG:
# info and Debug
OpenMaya.MGlobal.displayInfo(record.getMessage())
else:
OpenMaya.MGlobal.displayInfo(record.getMessage())
def setupMayaLogging(loggerName=''):
global MAYA_LOGGING_SETUP
log = logging.getLogger(loggerName)
if MAYA_LOGGING_SETUP:
return log
log.addHandler(MayaLogHandler())
log.setLevel(logging.INFO)
MAYA_LOGGING_SETUP = True
return log
# setup the mfxMaya logger
log = setupMayaLogging('mfxMaya')
This allow me to control my logging, and when I use the logging menu
from the pymel.tool I can even change the logging level of my package
which is really nice.
The problem I have is that because of the MayaLogHandler, I get double
logging, one from the handler and one from python. it looks somthing
like that in the script editor:
# Warning: Double underscores are not allowed in a description. #
mfxMaya.io.savesAs : WARNING : Double underscores are not allowed in a
description.
Do you know how I could only force only the MayaLogHandler to output?
I want to use the maya handler so that I can use the Maya color coding
of the warning and error message.
Thanks
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---