From 5a38a2563c0ee2d20cee1f010bdc764660da3ad2 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 1 Aug 2005 16:40:46 +0000 Subject: [PATCH] - Removed log4py dependency - Catch the unhandled exceptions git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@165 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/fail2ban b/fail2ban index abc9f9e2..f904271d 100755 --- a/fail2ban +++ b/fail2ban @@ -26,22 +26,28 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -from sys import exit, path +import sys, traceback, logging -# Appends our own modules path. Added before log4py import -# because log4py could be distributed with Fail2Ban. -path.append("/usr/lib/fail2ban") +# Appends our own modules path. +sys.path.append("/usr/lib/fail2ban") -# Checks for required libs -# Checks if log4py is present. -try: - import log4py -except: - print "log4py is needed (see README)" - exit(-1) - -# Now we can import our module +# Now we can import our module. import fail2ban -# Start the application -fail2ban.main() +# Gets the instance of the logger. +logSys = logging.getLogger("fail2ban") + +# Start the application. Handle all the unhandled exceptions +try: + fail2ban.main() +except SystemExit: + # We called sys.exit(). Nothing wrong so just pass + pass +except Exception, e: + (type, value, tb) = sys.exc_info() + tbStack = traceback.extract_tb(tb) + logSys.error("Fail2Ban got an unhandled exception and died.") + logSys.error("Type: " + `type.__name__` + "\n" + + "Value: " + `e.args` + "\n" + + "TB: " + `tbStack`) + logging.shutdown()