mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-12 00:15:51 -06:00
Use a rolling file appender for logs (from Nobuhiro Itou)
This commit is contained in:
parent
911f781687
commit
6a48f34bdc
1
AUTHORS
1
AUTHORS
@ -20,6 +20,7 @@ Further patches have been submitted by:
|
|||||||
Charles Coffing <ccoffing-at-novell-dot-com>
|
Charles Coffing <ccoffing-at-novell-dot-com>
|
||||||
Mark Cave-Ayland <mark.cave-ayland-at-ilande-dot-co-dot-uk>
|
Mark Cave-Ayland <mark.cave-ayland-at-ilande-dot-co-dot-uk>
|
||||||
Richard W.M. Jones <rjones-at-redhat-dot-com>
|
Richard W.M. Jones <rjones-at-redhat-dot-com>
|
||||||
|
Nobuhiro Itou <fj0873gn-at-aa-dot-jp-dot-fujitsu-dot-com>
|
||||||
|
|
||||||
<...send a patch & get your name here...>
|
<...send a patch & get your name here...>
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import sys
|
|||||||
import locale
|
import locale
|
||||||
import gettext
|
import gettext
|
||||||
import logging
|
import logging
|
||||||
|
import logging.handlers
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
gettext_app = "virt-manager"
|
gettext_app = "virt-manager"
|
||||||
@ -34,8 +35,16 @@ locale.setlocale(locale.LC_ALL, '')
|
|||||||
gettext.install(gettext_app, gettext_dir)
|
gettext.install(gettext_app, gettext_dir)
|
||||||
gettext.bindtextdomain(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
|
# 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):
|
if not os.access(vm_dir,os.W_OK):
|
||||||
try:
|
try:
|
||||||
os.mkdir(vm_dir)
|
os.mkdir(vm_dir)
|
||||||
@ -43,11 +52,13 @@ if not os.access(vm_dir,os.W_OK):
|
|||||||
raise RuntimeError, "Could not create %d directory: " % vm_dir, e
|
raise RuntimeError, "Could not create %d directory: " % vm_dir, e
|
||||||
|
|
||||||
# XXX should we get logging level from gconf, or command line args ?
|
# XXX should we get logging level from gconf, or command line args ?
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
filename = "%s/%s" % (vm_dir, FILE_NAME)
|
||||||
format="%(asctime)s %(levelname)-8s %(message)s",
|
rootLogger = logging.getLogger()
|
||||||
datefmt="%a, %d %b %Y %H:%M:%S",
|
rootLogger.setLevel(logging.DEBUG)
|
||||||
filename="%s/virt-manager.log" % vm_dir,
|
fileHandler = logging.handlers.RotatingFileHandler(filename, FILE_MODE, MAX_LOGSIZE, ROTATE_NUM)
|
||||||
filemode='w')
|
fileHandler.setFormatter(logging.Formatter(FILE_FORMAT, DATEFMT))
|
||||||
|
rootLogger.addHandler(fileHandler)
|
||||||
|
logging.info("Application startup")
|
||||||
|
|
||||||
# Urgh, pygtk merely logs a warning when failing to open
|
# Urgh, pygtk merely logs a warning when failing to open
|
||||||
# the X11 display connection, and lets everything carry
|
# the X11 display connection, and lets everything carry
|
||||||
@ -243,4 +254,7 @@ def main():
|
|||||||
gtk.gdk.threads_leave()
|
gtk.gdk.threads_leave()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
try:
|
||||||
|
main()
|
||||||
|
except Exception, e:
|
||||||
|
logging.exception(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user