14 May 2006 00:38
[patch 3/3] rework logging: add --verbose, deprecate --quiet
This patch reworks the debug logging in eoc, it deprecates the --quiet option (its description in the man-page is misleading, debug output is not sent to stderr by default) and adds a new --verbose option that causes debug output to be sent to stderr as well as the log file. --verbose is also made compatible with --no-log, then logging goes only to stderr. Signed-off-by: Johannes Berg <johannes@...> --- enemies-of-carlotta-1.2.1/enemies-of-carlotta.1 2006-05-13 23:56:36.181442681 +0200 +++ enemies-of-carlotta-1.2.1.new/enemies-of-carlotta.1 2006-05-13 23:57:24.081442681 +0200 <at> <at> -210,9 +210,11 <at> <at> is acceptable to the list, e.g., by checking digital signatures. .TP .BI \-\-quiet -By default, debugging log messages are sent to the standard error output -stream. -With this option, they aren't. +This option is ignored for backward compatibility. +.TP +.BI \-\-verbose +By default, debugging log messages are only saved to the log file. +With this option, they are also printed to stderr. .TP .BI \-\-sender= foo@... .TP --- enemies-of-carlotta-1.2.1/eoc.py 2006-05-13 23:56:36.181442681 +0200 +++ enemies-of-carlotta-1.2.1.new/eoc.py 2006-05-14 00:16:58.501442681 +0200 <at> <at> -1348,14 +1348,32 <at> <at> def write(self, str): pass +class Tee: + def __init__(self, one, two): + self.one = one + self.two = two + def write(self, str): + self.one.write(str) + self.two.write(str) + +verbose = 0 +no_log_file = 0 log_file_handle = None def log_file(): global log_file_handle if log_file_handle is None: - try: - log_file_handle = open(os.path.join(DOTDIR, "logfile.txt"), "a") - except: + if not no_log_file: + try: + log_file_handle = open(os.path.join(DOTDIR, "logfile.txt"), "a") + except: + log_file_handle = DevNull() + if verbose: + if log_file_handle is None: + log_file_handle = sys.stderr + else: + log_file_handle = Tee(log_file_handle, sys.stderr) + elif log_file_handle is None: log_file_handle = DevNull() return log_file_handle <at> <at> -1364,9 +1382,6 <at> <at> return time.strftime("%Y-%m-%d %H:%M:%S", tuple) + " [%d]" % os.getpid() -quiet = 0 - - # No logging to stderr of debug messages. Some MTAs have a limit on how # much data they accept via stderr and debug logs will fill that quickly. def debug(msg): <at> <at> -1405,6 +1420,7 <at> <at> --domain=domain.name --smtp-server=domain.name --quiet + --verbose --moderate --no-log <at> <at> -1479,6 +1495,7 <at> <at> "smtp-server=", "qmqp-server=", "quiet", + "verbose", "moderate", "post", "sender=", <at> <at> -1527,8 +1544,8 <at> <at> mail_on_forced_unsub = None mail_on_sub_changes = None no_act = 0 - global quiet - global log_file_handle + global verbose + global no_log_file for opt, arg in opts: if opt == "--name": <at> <at> -1570,11 +1587,14 <at> <at> elif opt == "--post": post = 1 elif opt == "--quiet": - quiet = 1 + # ignored for backward compatibility + pass + elif opt == "--verbose": + verbose = 1 elif opt == "--no-act": no_act = 1 elif opt == "--no-log": - log_file_handle = DevNull() + no_log_file = 1 else: operation = opt -- -- -- To unsubscribe, send mail to eoc-unsubscribe@... See the Enemies of Carlotta home page at <http://liw.iki.fi/liw/eoc/>
RSS Feed