haven't tested it yet (and i'll admit loggers still confuse me a bit)  
but i think what you want is to set log.propagate = False.  If i'm  
wrong Ofer will chime in shortly  :)

oh, also, one little nit-picky thing:  MAYA_LOGGING_SETUP is not a  
constant (since you changed the value), so it should not be all caps.   
most people don't even know that constants should be capitalized  
(based on PEP8 http://www.python.org/dev/peps/pep-0008/) so props for  
otherwise very good style.

-chad




On Oct 28, 2009, at 9:16 AM, sberger wrote:

>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to