Cando has proposed merging lp:~cando/zeitgeist/logging-fixed into lp:zeitgeist.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)
Related bugs:
  #660440 Using logging output for debugging purposes
  https://bugs.launchpad.net/bugs/660440


In this branch i've implemented the logging into a file feature, adding the 
improvements requested by Seif and Markus in this merge proposal:

https://code.launchpad.net/~ilidrissi.amine/zeitgeist/zeitgeist-logging/+merge/39237
-- 
https://code.launchpad.net/~cando/zeitgeist/logging-fixed/+merge/39781
Your team Zeitgeist Framework Team is requested to review the proposed merge of 
lp:~cando/zeitgeist/logging-fixed into lp:zeitgeist.
=== modified file '_zeitgeist/engine/__init__.py'
--- _zeitgeist/engine/__init__.py	2010-10-19 13:54:12 +0000
+++ _zeitgeist/engine/__init__.py	2010-11-01 20:58:45 +0000
@@ -48,6 +48,7 @@
 		BaseDirectory.save_data_path("zeitgeist"))
 	DATABASE_FILE = os.environ.get("ZEITGEIST_DATABASE_PATH",
 		os.path.join(DATA_PATH, "activity.sqlite"))
+	LOG_PATH = os.path.join(BaseDirectory.xdg_cache_home, "zeitgeist", "daemon.log")
 	
 	# D-Bus
 	DBUS_INTERFACE = ZeitgeistDBusInterface.INTERFACE_NAME

=== modified file 'zeitgeist-daemon.py'
--- zeitgeist-daemon.py	2010-10-20 10:24:42 +0000
+++ zeitgeist-daemon.py	2010-11-01 20:58:45 +0000
@@ -25,18 +25,18 @@
 import dbus.mainloop.glib
 import gettext
 import logging
+import logging.handlers
 import optparse
 import signal
 from subprocess import Popen, PIPE
+from xdg import BaseDirectory
 
 # Make sure we can find the private _zeitgeist namespace
 from zeitgeist import _config
 _config.setup_path()
 
-# Make sure we can load user extensions, and that they take priority over
-# system level extensions
 from _zeitgeist.engine import constants
-sys.path.insert(0, constants.USER_EXTENSION_PATH)
+LOG_PATH = constants.LOG_PATH
 
 gettext.install("zeitgeist", _config.localedir, unicode=True)
 
@@ -60,6 +60,7 @@
 	p.wait()
 	return p.stdout.read().strip() or None
 
+<<<<<<< TREE
 def parse_commandline():
 	parser = optparse.OptionParser(version = _config.VERSION, option_class=Options)
 	parser.add_option(
@@ -86,9 +87,50 @@
 	return parser
 
 def do_shell_completion(parser):
+=======
+class Options(optparse.Option):
+
+	TYPES = optparse.Option.TYPES + ("log_levels",)
+	TYPE_CHECKER = copy(optparse.Option.TYPE_CHECKER)
+	TYPE_CHECKER["log_levels"] = check_loglevel
+
+	log_levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
+
+parser = optparse.OptionParser(version = _config.VERSION, option_class=Options)
+parser.add_option(
+	"-r", "--replace",
+	action = "store_true", default=False, dest = "replace",
+	help = _("if another Zeitgeist instance is already running, replace it"))
+parser.add_option(
+	"--no-datahub", "--no-passive-loggers",
+	action = "store_false", default=True, dest = "start_datahub",
+	help = _("do not start zeitgeist-datahub automatically"))
+parser.add_option(
+	"--log-level",
+	action = "store", type="log_levels", default="DEBUG", dest="log_level",
+	help = _("how much information should be printed; possible values:") + \
+		" %s" % ', '.join(Options.log_levels))
+parser.add_option(
+	"--quit",
+	action = "store_true", default=False, dest = "quit",
+	help = _("if another Zeitgeist instance is already running, replace it"))
+parser.add_option(
+	"--shell-completion",
+	action = "store_true", default=False, dest = "shell_completion",
+	help = optparse.SUPPRESS_HELP)
+parser.add_option(
+	"--log-file",
+	action = "store", default = LOG_PATH, dest = "log_file",
+	help = _("Specifies where the log file is saved"))
+
+(_config.options, _config.arguments) = parser.parse_args()
+
+if _config.options.shell_completion:
+>>>>>>> MERGE-SOURCE
 	options = set()
 	for option in (str(option) for option in parser.option_list):
 		options.update(option.split("/"))
+<<<<<<< TREE
 	print " ".join(options)
 	return 0
 
@@ -100,6 +142,48 @@
 
 def start_datahub():
 	DATAHUB = "zeitgeist-datahub"
+=======
+	print ' '.join(options)
+	sys.exit(0)
+
+if _config.options.log_file == LOG_PATH:
+	try:
+		os.mkdir(os.path.join(BaseDirectory.xdg_cache_home, "zeitgeist"))
+	except OSError:
+		pass # directory is already there
+#	
+# Logger stuffs
+#
+logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
+                    level=getattr(logging, _config.options.log_level))
+
+# create the rotating file handler
+log_handler = logging.handlers.RotatingFileHandler(
+              filename=_config.options.log_file, maxBytes=20971520, backupCount=3)
+
+log_formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+log_handler.setFormatter(log_formatter)
+
+logging.getLogger().addHandler(log_handler)
+
+
+# Make sure we can load user extensions, and that they take priority over
+# system level extensions
+sys.path.insert(0, constants.USER_EXTENSION_PATH)
+
+from _zeitgeist.engine.remote import RemoteInterface
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+mainloop = gobject.MainLoop()
+
+try:
+	interface = RemoteInterface(mainloop = mainloop)
+except RuntimeError, e:
+	logging.error(unicode(e))
+	sys.exit(1)
+
+if _config.options.start_datahub:
+>>>>>>> MERGE-SOURCE
 	# hide all output of the datahub for now,
 	# in the future we might want to be more verbose here to make
 	# debugging easier in case sth. goes wrong with the datahub

_______________________________________________
Mailing list: https://launchpad.net/~zeitgeist
Post to     : zeitgeist@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zeitgeist
More help   : https://help.launchpad.net/ListHelp

Reply via email to