From: <los...@us...> - 2006-12-18 22:30:32
|
Revision: 493 http://svn.sourceforge.net/fail2ban/?rev=493&view=rev Author: lostcontrol Date: 2006-12-18 14:30:30 -0800 (Mon, 18 Dec 2006) Log Message: ----------- - Reset logging handlers only if new handler succeeds Modified Paths: -------------- trunk/server/server.py Modified: trunk/server/server.py =================================================================== --- trunk/server/server.py 2006-12-18 21:49:10 UTC (rev 492) +++ trunk/server/server.py 2006-12-18 22:30:30 UTC (rev 493) @@ -300,14 +300,18 @@ finally: self.__loggingLock.release() + ## + # Sets the logging target. + # + # target can be a file, SYSLOG, STDOUT or STDERR. + # @param target the logging target + def setLogTarget(self, target): try: self.__loggingLock.acquire() - # Remove previous handler - logging.getLogger("fail2ban").handlers = [] if target == "SYSLOG": facility = logging.handlers.SysLogHandler.LOG_DAEMON - hdlr = logging.handlers.SysLogHandler("/dev/log", + hdlr = logging.handlers.SysLogHandler("/dev/log", facility = facility) elif target == "STDOUT": hdlr = logging.StreamHandler(sys.stdout) @@ -320,8 +324,11 @@ hdlr = logging.FileHandler(target) except IOError: logSys.error("Unable to log to " + target) + logSys.info("Logging to previous target " + self.__logTarget) return False self.__logTarget = target + # Remove previous handler + logging.getLogger("fail2ban").handlers = [] # set a format which is simpler for console use formatter = logging.Formatter("%(asctime)s %(name)-16s: %(levelname)-6s %(message)s") # tell the handler to use this format This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <los...@us...> - 2007-03-22 22:17:58
|
Revision: 563 http://svn.sourceforge.net/fail2ban/?rev=563&view=rev Author: lostcontrol Date: 2007-03-22 15:17:41 -0700 (Thu, 22 Mar 2007) Log Message: ----------- - Close opened handlers. Thanks to Yaroslav Halchenko Modified Paths: -------------- trunk/server/server.py Modified: trunk/server/server.py =================================================================== --- trunk/server/server.py 2007-03-21 21:47:18 UTC (rev 562) +++ trunk/server/server.py 2007-03-22 22:17:41 UTC (rev 563) @@ -326,15 +326,18 @@ else: # Target should be a file try: - open(target, "a") + open(target, "a").close() hdlr = logging.FileHandler(target) except IOError: logSys.error("Unable to log to " + target) logSys.info("Logging to previous target " + self.__logTarget) return False self.__logTarget = target - # Remove previous handler - logging.getLogger("fail2ban").handlers = [] + # Removes previous handlers + for handler in logging.getLogger("fail2ban").handlers: + # Closes the handler. + handler.close() + logging.getLogger("fail2ban").removeHandler(handler) # set a format which is simpler for console use formatter = logging.Formatter("%(asctime)s %(name)-16s: %(levelname)-6s %(message)s") # tell the handler to use this format This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |