- Close opened handlers. Thanks to Yaroslav Halchenko

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@563 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 2007-03-22 22:17:41 +00:00
parent bf72fe7188
commit c768980784
1 changed files with 6 additions and 3 deletions

View File

@ -326,15 +326,18 @@ class Server:
else: else:
# Target should be a file # Target should be a file
try: try:
open(target, "a") open(target, "a").close()
hdlr = logging.FileHandler(target) hdlr = logging.FileHandler(target)
except IOError: except IOError:
logSys.error("Unable to log to " + target) logSys.error("Unable to log to " + target)
logSys.info("Logging to previous target " + self.__logTarget) logSys.info("Logging to previous target " + self.__logTarget)
return False return False
self.__logTarget = target self.__logTarget = target
# Remove previous handler # Removes previous handlers
logging.getLogger("fail2ban").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 # set a format which is simpler for console use
formatter = logging.Formatter("%(asctime)s %(name)-16s: %(levelname)-6s %(message)s") formatter = logging.Formatter("%(asctime)s %(name)-16s: %(levelname)-6s %(message)s")
# tell the handler to use this format # tell the handler to use this format