Zhou Zheng Sheng has uploaded a new change for review.

Change subject: logging: setup log filter correctly
......................................................................

logging: setup log filter correctly

logging.config.fileConfig() does not setup filters, it just setups
loggers, handlers and formatters. dictConfig() can setup filters but the
logging configuration is not very readable in a Python dict.

This patch subclass the log handler to be filtered, in the __init__()
method, add the filter need. Then in the logger.conf, use the subclass
instead of the original handler.

Change-Id: I76c2f77c95dd44853f070c8f7b7a8b71cfd6866c
Signed-off-by: Zhou Zheng Sheng <[email protected]>
---
M vdsm/logUtils.py
M vdsm/logger.conf.in
2 files changed, 16 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/88/9688/1

diff --git a/vdsm/logUtils.py b/vdsm/logUtils.py
index 933719d..8202bde 100644
--- a/vdsm/logUtils.py
+++ b/vdsm/logUtils.py
@@ -21,6 +21,7 @@
 import logging
 import sys
 from functools import wraps
+from logging.handlers import WatchedFileHandler
 from inspect import ismethod
 
 
@@ -160,3 +161,17 @@
             raise
         except:
             self.handleError(record)
+
+
+def getFilteredClass(logHandlerClass, *filters):
+    class Filtered(logHandlerClass):
+        def __init__(self, *args, **kwargs):
+            logHandlerClass.__init__(self, *args, **kwargs)
+            for aFilter in filters:
+                self.addFilter(aFilter)
+
+    return Filtered
+
+
+FilteredWatchedFileHandler = getFilteredClass(
+    WatchedFileHandler, TracebackRepeatFilter())
diff --git a/vdsm/logger.conf.in b/vdsm/logger.conf.in
index edd4616..cd42154 100644
--- a/vdsm/logger.conf.in
+++ b/vdsm/logger.conf.in
@@ -43,9 +43,8 @@
 args=('/dev/log', handlers.SysLogHandler.LOG_USER)
 
 [handler_logfile]
-class=logging.handlers.WatchedFileHandler
+class=logUtils.FilteredWatchedFileHandler
 args=('@VDSMLOGDIR@/vdsm.log',)
-filters=storage.misc.TracebackRepeatFilter
 level=DEBUG
 formatter=long
 


--
To view, visit http://gerrit.ovirt.org/9688
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I76c2f77c95dd44853f070c8f7b7a8b71cfd6866c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to