Remove the # character when using python logging

Remove the # character when using python logging

Anonymous
Not applicable
1,566 Views
5 Replies
Message 1 of 6

Remove the # character when using python logging

Anonymous
Not applicable

Hi!

 

We are trying to use the regular python logging instead of using prints.

I am using the maya.utils.MayaGuiLogHandler() as handler.

But any formatter I use, there is no way to get rid of the # in the script editor.

 

import logging

handler = maya.utils.MayaGuiLogHandler()
firstHandler = logger.handlers[0]
logger.addHandler(handler)
logger.removeHandler(firstHandler)
logger.propagate=False

logging.info("test")

Result is

 

# test #

How can I get rid of the #s ??

Thanks

0 Likes
1,567 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

using 

handler = logging.StreamHandler(sys.stdout)

Remove the # at the beginning of the log.

But I lost the behavior of 

maya.utils.MayaGuiLogHandler

that displays in the correct color in the Maya GUI

0 Likes
Message 3 of 6

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I think you can't remove the '#' with default logging handler. However, you can write your own handler, there is a template inside the pymel devkit folder(devkit\other\pymel\extras\completion\py\maya\utils.py) where you could start.

 

Yours,

Li

0 Likes
Message 4 of 6

Anonymous
Not applicable

Hi Li!

 

Thanks for the answer.

 

The # was printed because it seems that the default logging stream is stderr in Maya.

Using stdout instead is working ok to remove the #.

 

Now, I just want to be able to set color in the status line (without using the MGlobal.error or MGlobal.warning)

 

Do you have any idea how to do it?

ANd I will use my own handler

0 Likes
Message 5 of 6

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

In that case, I don't think Maya have a command or API for that. Sorry about that.

 

Yours,

Li

0 Likes
Message 6 of 6

Anonymous
Not applicable

**** 😄

 

Thanks

I will try to find a way then

0 Likes