parameters: (cp, handlers, disable_existing_loggers)
docstring: Create and install loggers
docstring_summary: Create and install loggers
docstring_tokens: Create and install loggers
function: def _install_loggers(cp, handlers, disable_existing_loggers):
      """Create and install loggers"""
  
      # configure the root first
      llist = cp.get("loggers", "keys")
      llist = llist.split(",")
      llist = list(map(lambda x: x.strip(), llist))
      llist.remove("root")
      sectname = "logger_root"
      root = logging.root
      log = root
      opts = cp.options(sectname)
      if "level" in opts:
          level = cp.get(sectname, "level")
          log.setLevel(logging._levelNames[level])
      for h in root.handlers[:]:
          root.removeHandler(h)
      hlist = cp.get(sectname, "handlers")
      if len(hlist):
          hlist = hlist.split(",")
          hlist = _strip_spaces(hlist)
          for hand in hlist:
              log.addHandler(handlers[hand])
  
      #and now the others...
      #we don't want to lose the existing loggers,
      #since other threads may have pointers to them.
      #existing is set to contain all existing loggers,
      #and as we go through the new configuration we
      #remove any which are configured. At the end,
      #what's left in existing is the set of loggers
      #which were in the previous configuration but
      #which are not in the new configuration.
      existing = list(root.manager.loggerDict.keys())
      #The list needs to be sorted so that we can
      #avoid disabling child loggers of explicitly
      #named loggers. With a sorted list it is easier
      #to find the child loggers.
      existing.sort(key=_encoded)
      #We'll keep the list of existing loggers
      #which are children of named loggers here...
      child_loggers = []
      #now set up the new ones...
      for log in llist:
          sectname = "logger_%s" % log
          qn = cp.get(sectname, "qualname")
          opts = cp.options(sectname)
          if "propagate" in opts:
              propagate = cp.getint(sectname, "propagate")
          else:
              propagate = 1
          logger = logging.getLogger(qn)
          if qn in existing:
              i = existing.index(qn) + 1 # start with the entry after qn
              prefixed = qn + "."
              pflen = len(prefixed)
              num_existing = len(existing)
              while i < num_existing:
                  if existing[i][:pflen] == prefixed:
                      child_loggers.append(existing[i])
                  i += 1
              existing.remove(qn)
          if "level" in opts:
              level = cp.get(sectname, "level")
              logger.setLevel(logging._levelNames[level])
          for h in logger.handlers[:]:
              logger.removeHandler(h)
          logger.propagate = propagate
          logger.disabled = 0
          hlist = cp.get(sectname, "handlers")
          if len(hlist):
              hlist = hlist.split(",")
              hlist = _strip_spaces(hlist)
              for hand in hlist:
                  logger.addHandler(handlers[hand])
  
      #Disable any old loggers. There's no point deleting
      #them as other threads may continue to hold references
      #and by disabling them, you stop them doing any logging.
      #However, don't disable children of named loggers, as that's
      #probably not what was intended by the user.
      for log in existing:
          logger = root.manager.loggerDict[log]
          if log in child_loggers:
              logger.level = logging.NOTSET
              logger.handlers = []
              logger.propagate = 1
          elif disable_existing_loggers:
              logger.disabled = 1
function_tokens: def _install_loggers ( cp , handlers , disable_existing_loggers ) : # configure the root first llist = cp . get ( "loggers" , "keys" ) llist = llist . split ( "," ) llist = list ( map ( lambda x : x . strip ( ) , llist ) ) llist . remove ( "root" ) sectname = "logger_root" root = logging . root log = root opts = cp . options ( sectname ) if "level" in opts : level = cp . get ( sectname , "level" ) log . setLevel ( logging . _levelNames [ level ] ) for h in root . handlers [ : ] : root . removeHandler ( h ) hlist = cp . get ( sectname , "handlers" ) if len ( hlist ) : hlist = hlist . split ( "," ) hlist = _strip_spaces ( hlist ) for hand in hlist : log . addHandler ( handlers [ hand ] ) #and now the others... #we don't want to lose the existing loggers, #since other threads may have pointers to them. #existing is set to contain all existing loggers, #and as we go through the new configuration we #remove any which are configured. At the end, #what's left in existing is the set of loggers #which were in the previous configuration but #which are not in the new configuration. existing = list ( root . manager . loggerDict . keys ( ) ) #The list needs to be sorted so that we can #avoid disabling child loggers of explicitly #named loggers. With a sorted list it is easier #to find the child loggers. existing . sort ( key = _encoded ) #We'll keep the list of existing loggers #which are children of named loggers here... child_loggers = [ ] #now set up the new ones... for log in llist : sectname = "logger_%s" % log qn = cp . get ( sectname , "qualname" ) opts = cp . options ( sectname ) if "propagate" in opts : propagate = cp . getint ( sectname , "propagate" ) else : propagate = 1 logger = logging . getLogger ( qn ) if qn in existing : i = existing . index ( qn ) + 1 # start with the entry after qn prefixed = qn + "." pflen = len ( prefixed ) num_existing = len ( existing ) while i < num_existing : if existing [ i ] [ : pflen ] == prefixed : child_loggers . append ( existing [ i ] ) i += 1 existing . remove ( qn ) if "level" in opts : level = cp . get ( sectname , "level" ) logger . setLevel ( logging . _levelNames [ level ] ) for h in logger . handlers [ : ] : logger . removeHandler ( h ) logger . propagate = propagate logger . disabled = 0 hlist = cp . get ( sectname , "handlers" ) if len ( hlist ) : hlist = hlist . split ( "," ) hlist = _strip_spaces ( hlist ) for hand in hlist : logger . addHandler ( handlers [ hand ] ) #Disable any old loggers. There's no point deleting #them as other threads may continue to hold references #and by disabling them, you stop them doing any logging. #However, don't disable children of named loggers, as that's #probably not what was intended by the user. for log in existing : logger = root . manager . loggerDict [ log ] if log in child_loggers : logger . level = logging . NOTSET logger . handlers = [ ] logger . propagate = 1 elif disable_existing_loggers : logger . disabled = 1