Looking at the source code, we can see the following:
root = RootLogger(WARNING) def getLogger(name=None): if name: return Logger.manager.getLogger(name) else: return root
That is, the root registrar is created by default when the module is imported. Therefore, every time you look for root looger (passing a false value, such as an empty string), you will get a logging.RootLogger object regardless of any call to logging.setLoggerClass .
As for the log class used, we can see:
_loggerClass = None def setLoggerClass(klass): ... _loggerClass = klass
This means that the global variable contains the log class that will be used in the future.
In addition to this, looking at logging.Manager (used by logging.getLogger ), we can see this:
def getLogger(self, name): ... rv = (self.loggerClass or _loggerClass)(name)
That is, if self.loggerClass not installed (which will not happen if you did not explicitly set it), the class from the global variable is used.
Therefore, this is a feature. The root log is always a logging.RootLogger object, and other log objects are created based on the configuration at that time.
jcollado
source share