In file 1:
def get_logger():
return logging.getLogger(_LOGGER_NAME)
def init_logger():
message_format = logging.Formatter(fmt='%(asctime)s %(name)s >>> %(message)s',
datefmt='%Y-%m-%d %H-%M-%S')
console_info_handler = logging.StreamHandler(sys.stdout)
console_info_handler.setLevel(logging.INFO)
console_info_handler.setFormatter(fmt=message_format)
logger = logging.getLogger(_LOGGER_NAME)
logger.addHandler(console_info_handler)
logger.setLevel(logging.INFO)
return logger
In file 2:
if name == '__main__':
logger = get_logger()
logger.info(logger.level)
Does not print anything (imports are in place of course). And if I go:
if __name__ == '__main__':
logger = get_logger()
logger.critical(logger.level)
The output is 0, instead of the expected 20. So it looks like the logger level isn't set at the level that I thought it was. Moreover, the level is lower than I thought it was, yet it still doesn't log on logger.info. What am I doing wrong here? Oh and bonus question (since I stole the above code and don't know any of python's logging intricacies), how does resolution of a log message happen if the logger's level and the handler's level clash?
_LOGGER_NAME?