diff --git a/server/filter.py b/server/filter.py index e9ff090b..42fb110d 100644 --- a/server/filter.py +++ b/server/filter.py @@ -64,7 +64,7 @@ class Filter(JailThread): self.__findTime = 6000 ## The ignore IP list. self.__ignoreIpList = [] - logSys.info("Created Filter") + logSys.debug("Created Filter") ## @@ -411,7 +411,7 @@ import md5 class FileContainer: - def __init__(self, filename, tail = False): + def __init__(self, filename, tail = True): self.__filename = filename self.__tail = tail self.__handler = None diff --git a/server/filtergamin.py b/server/filtergamin.py index 5907aaab..347f2ed8 100644 --- a/server/filtergamin.py +++ b/server/filtergamin.py @@ -53,7 +53,7 @@ class FilterGamin(FileFilter): self.__modified = False # Gamin monitor self.monitor = gamin.WatchMonitor() - logSys.info("Created FilterGamin") + logSys.debug("Created FilterGamin") def callback(self, path, event): @@ -69,7 +69,7 @@ class FilterGamin(FileFilter): # # @param path log file path - def addLogPath(self, path, tail = False): + def addLogPath(self, path, tail = True): if self.containsLogPath(path): logSys.error(path + " already exists") else: diff --git a/server/filterpoll.py b/server/filterpoll.py index 93fb995a..593f79b0 100644 --- a/server/filterpoll.py +++ b/server/filterpoll.py @@ -54,14 +54,14 @@ class FilterPoll(FileFilter): ## The time of the last modification of the file. self.__lastModTime = dict() self.__file404Cnt = dict() - logSys.info("Created FilterPoll") + logSys.debug("Created FilterPoll") ## # Add a log file path # # @param path log file path - def addLogPath(self, path, tail = False): + def addLogPath(self, path, tail = True): if self.containsLogPath(path): logSys.error(path + " already exists") else: diff --git a/server/jail.py b/server/jail.py index 363097a6..7b4a2719 100644 --- a/server/jail.py +++ b/server/jail.py @@ -37,6 +37,7 @@ class Jail: self.__name = name self.__queue = Queue.Queue() self.__filter = None + logSys.info("Creating new jail '%s'" % self.__name) if backend == "polling": self.__initPoller() else: @@ -47,14 +48,14 @@ class Jail: self.__action = Actions(self) def __initPoller(self): - logSys.info("Using poller") + logSys.info("Jail '%s' uses poller" % self.__name) from filterpoll import FilterPoll self.__filter = FilterPoll(self) def __initGamin(self): # Try to import gamin import gamin - logSys.info("Using Gamin") + logSys.info("Jail '%s' uses Gamin" % self.__name) from filtergamin import FilterGamin self.__filter = FilterGamin(self) @@ -82,12 +83,14 @@ class Jail: def start(self): self.__filter.start() self.__action.start() + logSys.info("Jail '%s' started" % self.__name) def stop(self): self.__filter.stop() self.__action.stop() self.__filter.join() self.__action.join() + logSys.info("Jail '%s' stopped" % self.__name) def isAlive(self): isAlive0 = self.__filter.isAlive() diff --git a/server/server.py b/server/server.py index 2a7e9b5c..973bfbfc 100644 --- a/server/server.py +++ b/server/server.py @@ -46,11 +46,11 @@ class Server: self.__daemon = daemon self.__transm = Transmitter(self) self.__asyncServer = AsyncServer(self.__transm) - self.__logLevel = 3 - self.__logTarget = "STDOUT" + self.__logLevel = None + self.__logTarget = None # Set logging level - self.setLogLevel(self.__logLevel) - self.setLogTarget(self.__logTarget) + self.setLogLevel(3) + self.setLogTarget("STDOUT") def __sigTERMhandler(self, signum, frame): logSys.debug("Caught signal %d. Exiting" % signum) @@ -66,6 +66,7 @@ class Server: # First set the mask to only allow access to owner os.umask(0077) if self.__daemon: + logSys.info("Starting in daemon mode") ret = self.__createDaemon() if ret: logSys.info("Daemon started") @@ -264,7 +265,7 @@ class Server: length = len(jailList) if not length == 0: jailList = jailList[:length-2] - ret = [("Number of jail", self.__jails.size()), + ret = [("Number of jail", self.__jails.size()), ("Jail list", jailList)] return ret finally: @@ -331,7 +332,7 @@ class Server: # Syslog daemons already add date to the message. formatter = logging.Formatter("%(name)-16s: %(levelname)-6s %(message)s") 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) @@ -346,7 +347,6 @@ class Server: logSys.error("Unable to log to " + target) logSys.info("Logging to previous target " + self.__logTarget) return False - self.__logTarget = target # Removes previous handlers for handler in logging.getLogger("fail2ban").handlers: # Closes the handler. @@ -355,6 +355,12 @@ class Server: # tell the handler to use this format hdlr.setFormatter(formatter) logging.getLogger("fail2ban").addHandler(hdlr) + # Does not display this message at startup. + if not self.__logTarget == None: + logSys.info("Changed logging target to %s for Fail2ban v%s" % + (target, version.version)) + # Sets the logging target. + self.__logTarget = target return True finally: self.__loggingLock.release()