Why logger.info('xxx') doesn't print message to maya script editor?

Hi , I want to use logging module in my script (in maya script editor) , but why this doesn’t work ?

import logging
logger = logging.getLogger('myLogger')
logger.setLevel(logging.INFO)

# the this should print out something right ?
logger.info('oh yeah this is something!')

Am I missing something ?

edit: I tried this, but unfortunately it doesn’t work either, only warn/error/critical show up.


import logging

logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)

ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

# prevent logging from bubbling up to maya's logger
logger.propagate=0

# application' code
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')

edit2: I know why now, in another module, there is some code disabled logging globally. after I run

logging.disable(logging.NOTSET)

logger.info and logger.debug start working

this helps “reenable” your temporarily disabled logger:


import logging 
class DisableLogger():
    def __enter__(self):
       logging.disable(logging.CRITICAL)
    def __exit__(self, a, b, c):
       logging.disable(logging.NOTSET)

# Example of use:

with DisableLogger():
    do_something()

import logging
logging.basicConfig()
logger = logging.getLogger('foo')
logger.info('dadsa')

a better solution for bigger libs is to use https://docs.python.org/2/library/logging.config.html#logging.config.dictConfig