[yum-cvs] yum/logginglevels.py

James Antill james at linux.duke.edu
Thu Jan 10 15:58:35 UTC 2008


 yum/logginglevels.py |   10 ++++++++++
 1 file changed, 10 insertions(+)

New commits:
commit cfc5d731eb924263e7b83b8aaa304870115cbd88
Author: James Antill <james at and.org>
Date:   Thu Jan 10 10:58:31 2008 -0500

     Fixes double messages when we call doConfigSetup() more than once, errorlevel
    etc. is still global which might be unexpected, but tough.
     Reproducer:
    
    import yum
    print "First time"
    prova = yum.YumBase()
    prova.doConfigSetup()
    print "Second time"
    prova2 = yum.YumBase()
    prova2.doConfigSetup()

diff --git a/yum/logginglevels.py b/yum/logginglevels.py
index b57a7cd..8b1b61b 100644
--- a/yum/logginglevels.py
+++ b/yum/logginglevels.py
@@ -86,6 +86,7 @@ def setErrorLevel(level):
     converted_level = logLevelFromErrorLevel(level)
     logging.getLogger("yum").setLevel(converted_level)
 
+_added_handlers = False
 def doLoggingSetup(debuglevel, errorlevel):
     """
     Configure the python logger.
@@ -95,9 +96,17 @@ def doLoggingSetup(debuglevel, errorlevel):
     debuglevel is optional. If provided, it will override the logging level
     provided in the logging config file for debug messages.
     """
+    global _added_handlers
 
     logging.basicConfig()
 
+    if _added_handlers:
+        if debuglevel is not None:
+            setDebugLevel(debuglevel)
+        if errorlevel is not None:  
+            setErrorLevel(errorlevel)
+        return
+
     plainformatter = logging.Formatter("%(message)s")
     syslogformatter = logging.Formatter("yum: %(message)s")
     
@@ -127,6 +136,7 @@ def doLoggingSetup(debuglevel, errorlevel):
         except socket.error:
             if syslog is not None:
                 syslog.close()
+    _added_handlers = True
 
     if debuglevel is not None:
         setDebugLevel(debuglevel)



More information about the Yum-cvs-commits mailing list