[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH] Log yum messages.



Jeremy Katz wrote:

While this looks like it'll work, it also looks like it might be a little fragile. I wonder if it's worth trying to get a better API in place that we could use to pass what we want to set. Alternately, we could just not use the base class's logging setup at all and do it all ourselves


You are right, there is not much gain in calling base class's logging setup, I am sending new version of patch that doesn't do it. As for better API, maybe addition of optional logging configuration files to yum (for yum and yum.verbose loggers) could be worthy, but I don't feel like diving into it right now.

Radek


>From 31a4b48a345bb18463f6fac7319593b379c11907 Mon Sep 17 00:00:00 2001
From: Radek Vykydal <rvykydal redhat com>
Date: Tue, 16 Jun 2009 16:48:05 +0200
Subject: [PATCH] Log yum messages.

Overrides base class function: sets handlers for "yum" and "yum.verbose"
- loggers that yum is using. Logs into tty3 and with more detail into yum.log.
---
 packages.py   |    3 ++-
 yuminstall.py |   28 +++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/packages.py b/packages.py
index ba2f9e3..0721923 100644
--- a/packages.py
+++ b/packages.py
@@ -82,7 +82,8 @@ def copyAnacondaLogs(anaconda):
                        ("/tmp/syslog", "anaconda.syslog"),
                        ("/tmp/X.log", "anaconda.xlog"),
                        ("/tmp/program.log", "program.log"),
-                       ("/tmp/storage.log", "storage.log")):
+                       ("/tmp/storage.log", "storage.log"),
+                       ("/tmp/yum.log", "yum.log")):
         if os.access(fn, os.R_OK):
             try:
                 shutil.copyfile(fn, "%s/var/log/%s" %(anaconda.rootPath, dest))
diff --git a/yuminstall.py b/yuminstall.py
index 7063595..6be1baa 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -579,7 +579,33 @@ class AnacondaYum(YumSorter):
 
     # Override this method so yum doesn't nuke our existing logging config.
     def doLoggingSetup(self, *args, **kwargs):
-        pass
+
+        import yum.logginglevels
+
+        file_handler = logging.FileHandler("/tmp/yum.log")
+        file_formatter = logging.Formatter("[%(asctime)s] %(levelname)-8s: %(message)s")
+        file_handler.setFormatter(file_formatter)
+
+        tty3_handler = logging.FileHandler("/dev/tty3")
+        tty3_formatter = logging.Formatter("%(asctime)s %(levelname)-8s: %(name)s: %(message)s", "%H:%M:%S")
+        tty3_handler.setFormatter(tty3_formatter)
+
+        verbose = logging.getLogger("yum.verbose")
+        verbose.setLevel(yum.logginglevels.DEBUG_2)
+        verbose.propagate = False
+        verbose.addHandler(file_handler)
+
+        logger = logging.getLogger("yum")
+        logger.propagate = False
+        logger.setLevel(yum.logginglevels.INFO_2)
+        logger.addHandler(file_handler)
+        logger.addHandler(tty3_handler)
+
+        # XXX filelogger is set in setFileLog - do we or user want it?
+        filelogger = logging.getLogger("yum.filelogging")
+        filelogger.setLevel(logging.INFO)
+        filelogger.propagate = False
+
 
     def doConfigSetup(self, fn='/tmp/anaconda-yum.conf', root='/'):
         if hasattr(self, "preconf"):
-- 
1.6.0.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]