Why there is always a ‘#’ when I use my logger even propagation is off already?

27 views
Skip to first unread message

oglop

unread,
Jul 16, 2016, 1:38:37 PM7/16/16
to Python Programming for Autodesk Maya


import logging
_logger
= logging.getLogger('myLogger')

for handler in _logger.handlers:
    _logger
.removeHandler(handler)

ch
= logging.StreamHandler()
ch
.setLevel(logging.INFO)
formatter
= logging.Formatter('%(name)s:%(levelname)s: %(message)s')
ch
.setFormatter(formatter)
_logger
.addHandler(ch)
_logger
.propagate=0

_logger
.info('yeah')
# myLogger:INFO: yeah

I have set propagate to off already, where does the '#' come from when I use _logger in maya 2015?

Justin Israel

unread,
Jul 16, 2016, 4:40:06 PM7/16/16
to python_in...@googlegroups.com
It is because your logging is going to stderr, and Maya assigns a custom stderr and hides the original one:

import sys

# Maya installs this one so it goes to Script Editor
sys.stderr.write("stderr\n")

# The original one that Maya saves
sys.__stderr__.write("__stderr__\n")

Justin

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c6cf48a7-6e51-4060-b606-d3ab4999a300%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

oglop

unread,
Jul 17, 2016, 3:40:56 AM7/17/16
to Python Programming for Autodesk Maya
Thanks! After changing this line to

ch = logging.StreamHandler(sys.stdout)

The '#' goes away.


On Saturday, July 16, 2016 at 1:40:06 PM UTC-7, Justin Israel wrote:
On Sun, Jul 17, 2016 at 5:38 AM oglop <ogl...@gmail.com> wrote:


import logging
_logger
= logging.getLogger('myLogger')

for handler in _logger.handlers:
    _logger
.removeHandler(handler)

ch
= logging.StreamHandler()
ch
.setLevel(logging.INFO)
formatter
= logging.Formatter('%(name)s:%(levelname)s: %(message)s')
ch
.setFormatter(formatter)
_logger
.addHandler(ch)
_logger
.propagate=0

_logger
.info('yeah')
# myLogger:INFO: yeah

I have set propagate to off already, where does the '#' come from when I use _logger in maya 2015?

It is because your logging is going to stderr, and Maya assigns a custom stderr and hides the original one:

import sys

# Maya installs this one so it goes to Script Editor
sys.stderr.write("stderr\n")

# The original one that Maya saves
sys.__stderr__.write("__stderr__\n")

Justin

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages