Logger.getChild() incompatible with Python 2.6
Closed this issue ยท 4 comments
Logger.getChild() doesn't exist until Python 2.7. PyPXE is supposed to support Python 2.6, which is the latest normally available on CentOS 6. Can we see about implementing a workaround so we can still support older versions of Python?
So we use .getChild()
in 4 places at the moment. Three are at the root level (PyPXE.[thing]
) and one is at the level below. I propose we create our own getChild
implementation similar to the following:
def getChild(logger, name):
return logging.getLogger("{0}.{1}".format(logger.name, name))
A full example follows:
import logging
def getChild(logger, name):
return logging.getLogger("{0}.{1}".format(logger.name, name))
sys_logger = logging.getLogger('PyPXE')
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(name)s %(message)s')
handler.setFormatter(formatter)
sys_logger.addHandler(handler)
sys_logger.setLevel(logging.INFO)
sys_logger.info("foo")
getChild(sys_logger, "bar").info("baz")
bash-3.2$ python2.6 test.py
2016-06-03 09:09:19,411 [INFO] PyPXE foo
2016-06-03 09:09:19,411 [INFO] PyPXE.bar baz
It would be easy to subclass the Logger object, but may add uneccessary complexity.
Opinions?
That looks reasonable to me, and works as expected in Python 2.6. Thanks!
If you've got this working locally would you be able to submit a PR? I can't get to my dev box for a while at the moment.
Sure. I should be able to get to it this weekend.