[Mpuls-commits] r5176 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Jul 19 14:12:26 CEST 2011
Author: ludwig
Date: 2011-07-19 14:12:25 +0200 (Tue, 19 Jul 2011)
New Revision: 5176
Added:
base/trunk/mpulsweb/lib/logfilter.py
Modified:
base/trunk/ChangeLog
Log:
Issue 2009: Added support for logging with the name of the database.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2011-07-19 10:04:37 UTC (rev 5175)
+++ base/trunk/ChangeLog 2011-07-19 12:12:25 UTC (rev 5176)
@@ -1,3 +1,13 @@
+2011-07-19 Ludwig Reiter <ludwig.reiter at intevation.de>
+
+ * mpulsweb/lib/logfilter.py:
+ Issue 2009: Added support for logging with the name of the database.
+ A configuration of the ini file is needed, if this feature should be
+ used. ( Use the class DBNameHandler as handler to add the filter to
+ the handler and add "%(dbname)s" to the default formatter to
+ display the dbname.)
+ The get db name method used by the filter is not optimal at the moment.
+
2011-07-19 Torsten Irländer <torsten.irlaender at intevation.de>
* mpulsweb/templates/phase/dialogs/success_halfautomatic_set_phase.mako:
Added: base/trunk/mpulsweb/lib/logfilter.py
===================================================================
--- base/trunk/mpulsweb/lib/logfilter.py 2011-07-19 10:04:37 UTC (rev 5175)
+++ base/trunk/mpulsweb/lib/logfilter.py 2011-07-19 12:12:25 UTC (rev 5176)
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+#
+# Authors:
+# Ludwig Reiter <ludwig.reiter at intevation.de>
+
+import logging
+import mpulsweb.lib.security as security
+
+log = logging.getLogger(__name__)
+
+class DBNameContextFilter(logging.Filter):
+ """
+ This filter injects the dbname into a log message.
+
+ It tries to get the dbname from the security module and
+ catches all exceptions from there.
+ """
+
+ def get_dbname(self):
+ dbname = None
+ try:
+ dbname = security.getDbName()
+ except:
+ log.debug("Cannot find db name")
+ return dbname
+
+ def filter(self, record):
+ record.dbname = self.get_dbname()
+
+ return True
+
+class DBNameHandler(logging.StreamHandler):
+ """
+ Handler with DBNameContextFilter.
+ """
+ def __init__(self, *args, **kwargs):
+ logging.StreamHandler.__init__(self, *args, **kwargs)
+ self.addFilter(DBNameContextFilter())
More information about the Mpuls-commits
mailing list