[et-mgmt-tools] [PATCH] Fix virt-manager.log problem

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

 



Hi,

Now, there are the following problems in virt-manager.log.
- The content of virt-manager.log is overwritten at the start
  time of virt-manager.
- The log size is keeps increasing infinitely, if it keeps
  using virt-manager.
The attached patch adds to solve these problems.

It is change points as follows.
 * File mode           -- append
 * Log size            -- 1MB(1024*1024)
 * Number of Rotations -- 5

Signed-off-by: Nobuhiro Itou <fj0873gn@xxxxxxxxxxxxxxxxx>


Thanks,
Nobuhiro Itou.


---------------------------------------------------
diff -r 1538611b315d src/virt-manager.py.in
--- a/src/virt-manager.py.in	Fri May 11 10:40:24 2007 -0400
+++ b/src/virt-manager.py.in	Fri May 18 12:02:52 2007 +0900
@@ -25,6 +25,7 @@ import locale
 import locale
 import gettext
 import logging
+import logging.handlers
 import traceback
 
 gettext_app = "virt-manager"
@@ -34,8 +35,16 @@ gettext.install(gettext_app, gettext_dir
 gettext.install(gettext_app, gettext_dir)
 gettext.bindtextdomain(gettext_app, gettext_dir)
 
+MAX_LOGSIZE   = 1024 * 1024  # 1MB
+ROTATE_NUM    = 5
+DIR_NAME      = ".virt-manager"
+FILE_NAME     = "virt-manager.log"
+FILE_MODE     = 'a'
+FILE_FORMAT   = "[%(asctime)s virt-manager %(process)d] %(levelname)s (%(module)s:%(lineno)d) %(message)s"
+DATEFMT       = "%a, %d %b %Y %H:%M:%S"
+
 # set up logging
-vm_dir = os.path.expanduser("~/.virt-manager")
+vm_dir = os.path.expanduser("~/%s" % DIR_NAME)
 if not os.access(vm_dir,os.W_OK):
     try:
         os.mkdir(vm_dir)
@@ -43,11 +52,12 @@ if not os.access(vm_dir,os.W_OK):
         raise RuntimeError, "Could not create %d directory: " % vm_dir, e
 
 # XXX should we get logging level from gconf, or command line args ?
-logging.basicConfig(level=logging.DEBUG,
-                    format="%(asctime)s %(levelname)-8s %(message)s",
-                    datefmt="%a, %d %b %Y %H:%M:%S",
-                    filename="%s/virt-manager.log" % vm_dir,
-                    filemode='w')
+filename = "%s/%s" % (vm_dir, FILE_NAME)
+rootLogger = logging.getLogger()
+rootLogger.setLevel(logging.DEBUG)
+fileHandler = logging.handlers.RotatingFileHandler(filename, FILE_MODE, MAX_LOGSIZE, ROTATE_NUM)
+fileHandler.setFormatter(logging.Formatter(FILE_FORMAT, DATEFMT))
+rootLogger.addHandler(fileHandler)
 
 # Urgh, pygtk merely logs a warning when failing to open
 # the X11 display connection, and lets everything carry
@@ -243,4 +253,7 @@ def main():
         gtk.gdk.threads_leave()
 
 if __name__ == "__main__":
-    main()
+    try:
+        main()
+    except Exception, e:
+        logging.exception(e)


[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux