def __init__(self, methodName='runTest'): log.FluLogKeeper.init('test.log') log.set_default(log.FluLogKeeper()) log.Logger.__init__(self, log.get_default()) unittest.TestCase.__init__(self, methodName) self.debug('SeleniumTest.__init__: finished')
def testDefaultLogging(self): keeper = DummyLogKeeper() log.set_default(keeper) log.log("foo", "1") log.debug("bar", "2", 42) log.info("spam", "3") log.warning("bacon", "4", 2, 3, 5) log.error("eggs", "4") self.assertEqual(keeper.entries, [(LogLevel.log, None, 'foo', '1', (), 1), (LogLevel.debug, None, 'bar', '2', (42, ), 1), (LogLevel.info, None, 'spam', '3', (), 1), (LogLevel.warning, None, 'bacon', '4', (2, 3, 5), 1), (LogLevel.error, None, 'eggs', '4', (), 1)])
def testDefaultLogging(self): keeper = DummyLogKeeper() current = log.get_default() log.set_default(keeper) self.addCleanup(log.set_default, current) log.log("foo", "1") log.debug("bar", "2", 42) log.info("spam", "3") log.warning("bacon", "4", 2, 3, 5) log.error("eggs", "4") self.assertEqual( keeper.entries, [ (LogLevel.log, None, "foo", "1", (), 1), (LogLevel.debug, None, "bar", "2", (42,), 1), (LogLevel.info, None, "spam", "3", (), 1), (LogLevel.warning, None, "bacon", "4", (2, 3, 5), 1), (LogLevel.error, None, "eggs", "4", (), 1), ], )
def handle(self, addrport='', *args, **options): if args: raise CommandError('Usage is server %s' % self.args) if not addrport: self.addr = '' self.port = DEFAULT_PORT else: m = re.match(naiveip_re, addrport) if m is None: raise CommandError('"%s" is not a valid port number ' 'or address:port pair.' % addrport) self.addr, _ipv4, _ipv6, _fqdn, self.port = m.groups() if not self.port.isdigit(): raise CommandError("%r is not a valid port number." % self.port) if self.addr and _ipv6: raise CommandError("ipv6 is not supported") if not self.addr: self.addr = '127.0.0.1' if options.get('apiprefix') and not options.get('prefix'): raise CommandError("--apiprefix can only be used in conjuction " "with --prefix. ") logger = logging.getLogger('feat') if options.get('featlog'): log.FluLogKeeper.init(options['featlog']) log.set_default(log.FluLogKeeper()) log.info('featdjango', 'Use feat logging: %s' % (options['featlog'], )) else: log.set_default(log.PythonLogKeeper(logger)) from feat.extern.log import log as flulog flulog.setPackageScrubList('featcredex', 'featdjango', 'feat') log.info('featdjango', 'Use python logging') log.info('featdjango', "Listening on %s:%s", self.addr, self.port) if os.environ.get("RUN_MAIN") == 'true': # this is how django autoreloader lets the child process know # that its a child process if options.get('elflog_path'): stats = webserver.ELFLog(options.get('elflog_path'), options.get('elflog_fields')) else: stats = None site = server.Server(self.addr, int(self.port), prefix=options.get('prefix'), apiprefix=options.get('apiprefix'), web_statistics=stats, thread_stats_file=options.get('stats_file')) reactor.callWhenRunning(site.initiate) reactor.addSystemEventTrigger('before', 'shutdown', site.cleanup) if options.get('use_reloader'): task = reloader.Reloader(reactor, site) reactor.callWhenRunning(task.run) reactor.run() if options.get('use_reloader'): if task.should_reload: sys.exit(3) else: # in the original process we just spawn the child worker as # many times as it tells us to try: while autoreload.restart_with_reloader() == 3: pass except KeyboardInterrupt: pass
def handle(self, addrport='', *args, **options): if args: raise CommandError('Usage is server %s' % self.args) if not addrport: self.addr = '' self.port = DEFAULT_PORT else: m = re.match(naiveip_re, addrport) if m is None: raise CommandError('"%s" is not a valid port number ' 'or address:port pair.' % addrport) self.addr, _ipv4, _ipv6, _fqdn, self.port = m.groups() if not self.port.isdigit(): raise CommandError( "%r is not a valid port number." % self.port) if self.addr and _ipv6: raise CommandError("ipv6 is not supported") if not self.addr: self.addr = '127.0.0.1' if options.get('apiprefix') and not options.get('prefix'): raise CommandError("--apiprefix can only be used in conjuction " "with --prefix. ") logger = logging.getLogger('feat') if options.get('featlog'): log.FluLogKeeper.init(options['featlog']) log.set_default(log.FluLogKeeper()) log.info('featdjango', 'Use feat logging: %s' % ( options['featlog'], )) else: log.set_default(log.PythonLogKeeper(logger)) from feat.extern.log import log as flulog flulog.setPackageScrubList('featcredex', 'featdjango', 'feat') log.info('featdjango', 'Use python logging') log.info('featdjango', "Listening on %s:%s", self.addr, self.port) if os.environ.get("RUN_MAIN") == 'true': # this is how django autoreloader lets the child process know # that its a child process if options.get('elflog_path'): stats = webserver.ELFLog(options.get('elflog_path'), options.get('elflog_fields')) else: stats = None site = server.Server(self.addr, int(self.port), prefix=options.get('prefix'), apiprefix=options.get('apiprefix'), web_statistics=stats, thread_stats_file=options.get('stats_file')) reactor.callWhenRunning(site.initiate) reactor.addSystemEventTrigger('before', 'shutdown', site.cleanup) if options.get('use_reloader'): task = reloader.Reloader(reactor, site) reactor.callWhenRunning(task.run) reactor.run() if options.get('use_reloader'): if task.should_reload: sys.exit(3) else: # in the original process we just spawn the child worker as # many times as it tells us to try: while autoreload.restart_with_reloader() == 3: pass except KeyboardInterrupt: pass