mirror of https://github.com/fail2ban/fail2ban
- Reset logging handlers only if new handler succeeds
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@493 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
b02394fd23
commit
5dd2c5162e
|
@ -300,14 +300,18 @@ class Server:
|
||||||
finally:
|
finally:
|
||||||
self.__loggingLock.release()
|
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):
|
def setLogTarget(self, target):
|
||||||
try:
|
try:
|
||||||
self.__loggingLock.acquire()
|
self.__loggingLock.acquire()
|
||||||
# Remove previous handler
|
|
||||||
logging.getLogger("fail2ban").handlers = []
|
|
||||||
if target == "SYSLOG":
|
if target == "SYSLOG":
|
||||||
facility = logging.handlers.SysLogHandler.LOG_DAEMON
|
facility = logging.handlers.SysLogHandler.LOG_DAEMON
|
||||||
hdlr = logging.handlers.SysLogHandler("/dev/log",
|
hdlr = logging.handlers.SysLogHandler("/dev/log",
|
||||||
facility = facility)
|
facility = facility)
|
||||||
elif target == "STDOUT":
|
elif target == "STDOUT":
|
||||||
hdlr = logging.StreamHandler(sys.stdout)
|
hdlr = logging.StreamHandler(sys.stdout)
|
||||||
|
@ -320,8 +324,11 @@ class Server:
|
||||||
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)
|
||||||
return False
|
return False
|
||||||
self.__logTarget = target
|
self.__logTarget = target
|
||||||
|
# Remove previous handler
|
||||||
|
logging.getLogger("fail2ban").handlers = []
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in New Issue