From 1f3e33e384bb913ac5bb7a3743d50719e62c9a05 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 4 Jul 2006 03:36:39 +0000 Subject: [PATCH] added verbosity patch from one of my branches --- debian/changelog | 1 + debian/patches/00_verbosity.dpatch | 95 ++++++++++++++++++++++++++++++ debian/patches/00list | 5 +- 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100755 debian/patches/00_verbosity.dpatch diff --git a/debian/changelog b/debian/changelog index a9979fce..1181612c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ fail2ban (0.6.1-10) unstable; urgency=low message * Added configuration parameter "locale" to specify LC_TIME for time pattern matching (closes: #367990,363391) + * Verbosity is chosen to be max between cmdline parameters and config file -- Yaroslav Halchenko Mon, 3 Jul 2006 21:59:34 -0400 diff --git a/debian/patches/00_verbosity.dpatch b/debian/patches/00_verbosity.dpatch new file mode 100755 index 00000000..a34f9fe2 --- /dev/null +++ b/debian/patches/00_verbosity.dpatch @@ -0,0 +1,95 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 00_verbosity.dpatch by +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: Verbosity can be set either from command line or from config file. +## DP: Logically the maximal verbosity from two of them should be chosen since +## DP: verbosity from cmdline can't simple increase config file verbosity +## DP: because config line might not be even read yet + +@DPATCH@ + +diff -x '*~' -Naur fail2ban-0.6.1.pre/fail2ban.py fail2ban-0.6.1.post/fail2ban.py +--- fail2ban-0.6.1.pre/fail2ban.py 2006-03-19 00:20:44.000000000 -0500 ++++ fail2ban-0.6.1.post/fail2ban.py 2006-07-03 23:29:58.000000000 -0400 +@@ -161,9 +161,11 @@ + """ + # enabledsections can be defined just from the command line + conf["enabledsections"] = [] ++ # by default we are silent ++ cmdLineVerbose = 0 + for opt in optList: + if opt[0] == "-v": +- conf["verbose"] = conf["verbose"] + 1 ++ cmdLineVerbose += 1 + if opt[0] == "-b": + conf["background"] = True + if opt[0] == "-d": +@@ -192,6 +194,30 @@ + conf["enabledsections"] = map(lambda x: x.upper(), + re.split("[:, \t\n]", opt[1])) + ++ # Let's choose the maximal verbosity from cmdLine and config ++ # files: it would better describe the intent of the user ++ conf["verbose"] = max(cmdLineVerbose, conf["verbose"]) ++ ++ ++presetVerbosityLevel = 0 ++def setVerbosityLevel(level): ++ """ Sets verbosity level if previousely set one is different ++ """ ++ global presetVerbosityLevel ++ # Verbose level ++ if level != presetVerbosityLevel and level: ++ logSys.warn("Verbose level is %d"%level) ++ if level == 1: ++ logSys.setLevel(logging.INFO) ++ elif level > 1: ++ logSys.setLevel(logging.DEBUG) ++ if conf["verbose"] > 2: ++ formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' + ++ '%(message)s') ++ formatter = logging.Formatter("%(asctime)s " + formatterstring) ++ stdout.setFormatter(formatter) ++ presetVerbosityLevel = level ++ + def main(): + """ Fail2Ban main function + """ +@@ -220,12 +246,16 @@ + + # Pre-parsing of command line options for the -c option + for opt in optList: ++ if opt[0] == "-v": ++ conf["verbose"] = conf["verbose"] + 1 + if opt[0] == "-c": + conf["conffile"] = opt[1] + if opt[0] in ["-h", "--help"]: + dispUsage() + if opt[0] in ["-V", "--version"]: + dispVersion() ++ ++ setVerbosityLevel(conf['verbose']) + + # Reads the config file and create a LogReader instance for + # each log file to check. +@@ -337,18 +367,7 @@ + hdlr.setFormatter(tformatter) + logSys.addHandler(hdlr) + +- # Verbose level +- if conf["verbose"]: +- logSys.warn("Verbose level is "+`conf["verbose"]`) +- if conf["verbose"] == 1: +- logSys.setLevel(logging.INFO) +- elif conf["verbose"] > 1: +- logSys.setLevel(logging.DEBUG) +- if conf["verbose"] > 2: +- formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' + +- '%(message)s') +- formatter = logging.Formatter("%(asctime)s " + formatterstring) +- stdout.setFormatter(formatter) ++ setVerbosityLevel(conf['verbose']) + + # Debug mode. Should only be used by developers + if conf["debug"]: diff --git a/debian/patches/00list b/debian/patches/00list index d3003abd..1e691767 100644 --- a/debian/patches/00list +++ b/debian/patches/00list @@ -1,6 +1,7 @@ +00_empty_ip +00_locale_config +00_verbosity 00_proftpd_section 00_vsftpd_regexp 01_apache2_other 02_sasl_section -00_empty_ip -00_locale_config