[prev in list] [next in list] [prev in thread] [next in thread] 

List:       prelude-cvslog
Subject:    [prelude-cvslog] prelude-correlator/master: Python 2.4 backward
From:       noreply () prelude-ids ! com
Date:       2009-09-15 6:47:17
Message-ID: 20090915064717.5DB043C8001 () inferno ! prelude-ids ! com
[Download RAW message or body]

commit f6e8e61145ce659ef6c97b15225918bf2a48f824
Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
Date:   Fri Sep 11 12:09:34 2009 +0200

    Python 2.4 backward compatibility
    
    The logging 'extra' keyword is only available in Python 2.5 and higher,
    do not use it when running an older Python version.


========================================

 PreludeCorrelator/log.py |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

========================================

diff --git a/PreludeCorrelator/log.py b/PreludeCorrelator/log.py
index ee612d1..2e54cdd 100644
--- a/PreludeCorrelator/log.py
+++ b/PreludeCorrelator/log.py
@@ -49,26 +49,37 @@ class Log(logging.Logger):
                 # PreludeLog is available in recent libprelude version, we do not \
want to fail if it's not.  pass
 
+        self._have_extra = sys.version_info > (2, 4)
         try:
                 logging.config.fileConfig(conf_filename)
         except Exception, e:
                 DATEFMT = "%d %b %H:%M:%S"
-                FORMAT="%(asctime)s (process:%(pid)d) %(levelname)s: %(message)s"
+                if not self._have_extra:
+                        FORMAT="%(asctime)s %(levelname)s: %(message)s"
+                else:
+                        FORMAT="%(asctime)s (process:%(pid)d) %(levelname)s: \
%(message)s" +
                 logging.basicConfig(level=logging.DEBUG, format=FORMAT, \
datefmt=DATEFMT, stream=sys.stderr)  
         self._logger = logging.getLogger("prelude-correlator")
 
+    def _log(self, log_func, log, extra):
+        if self._have_extra:
+                log_func(log, extra=extra)
+        else:
+                log_func(log)
+
     def debug(self, log):
-        self._logger.debug(log, extra = { "pid": os.getpid() })
+        self._log(self._logger.debug, log, extra = { "pid": os.getpid() })
 
     def info(self, log):
-        self._logger.info(log, extra = { "pid": os.getpid() })
+        self._log(self._logger.info, log, extra = { "pid": os.getpid() })
 
     def warning(self, log):
-        self._logger.warning(log, extra = { "pid": os.getpid() })
+        self._log(self._logger.warning, log, extra = { "pid": os.getpid() })
 
     def error(self, log):
-        self._logger.error(log, extra = { "pid": os.getpid() })
+        self._log(self._logger.error, log, extra = { "pid": os.getpid() })
 
     def critical(self, log):
-        self._logger.critical(log, extra = { "pid": os.getpid() })
+        self._log(self._logger.critical, log, extra = { "pid": os.getpid() })
_______________________________________________
Prelude-cvslog site list
Prelude-cvslog@prelude-ids.org
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic