def testLogtofile(self): "Test logging to a StringIO file." si = StringIO.StringIO() log.usestderr(si) log.setprogname("foobar") log.setdebuglevel(3) log.warn("string 1") log.debug(2, "string 2") log.debug(3, "string 3") log.debug(4, "string 4") self.assertEqual(si.getvalue(), "foobar: string 1\nfoobar: string 2\nfoobar: string 3\n")
def usage(): log.die("usage: portnanny2 [-v|-V NUM] [-M MAXTHREADS] [-S STACK] [-C] [-l] conffile") def main(sargs): usesyslog = 0 checkonly = 0 threadmax = None stacklim = None try: opts, args = getopt.getopt(sargs, "vV:p:lCM:S:", []) except getopt.error, cause: log.warn(str(cause)) usage() for o, a in opts: if o == '-v': log.setdebuglevel(1) elif o == '-V': log.setdebuglevel(int(a)) elif o == '-p': log.setprogname(a) elif o == '-l': usesyslog = 1 elif o == '-C': checkonly = 1 elif o == '-S': if a == 'unlimited': stacklim = -1L else: try: stacklim = int(a)*1024L except ValueError: