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. |