def init(cls, path=None): global flulog if not cls._initialized: if path: sys.stderr = file(path, 'a') from feat.extern.log import log as flulog flulog.init('FEAT_DEBUG') flulog.setPackageScrubList('feat', 'twisted') flulog.logTwisted() if get_default() is None: set_default(cls()) cls._initialized = True
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