def run(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.logger.info("Binding to %s:%s", self.bind_ip, self.bind_port) s.bind((self.bind_ip, self.bind_port)) s.listen(20) while True: client, address = s.accept() self.logger.debug("Accepting connection from %s:%s", *address) client_file = client.makefile("rb+", 1) json_data = client_file.read() conf = Values(json.loads(json_data)) self.logger.info( "Starting run for %s:%s [put/get/del_concurrency: %s/%s/%s, " "num_objects: %s, num_gets: %s]", address[0], address[1], conf.put_concurrency, conf.get_concurrency, conf.del_concurrency, conf.num_objects, conf.num_gets, ) logger = logging.getLogger("bench-server") level = logging.DEBUG if conf.log_level.lower() == "debug" else logging.INFO logger.setLevel(level) loghandler = logging.StreamHandler(client_file) logformat = logging.Formatter("%(server)s %(asctime)s %(levelname)s %(message)s") loghandler.setFormatter(logformat) logger.addHandler(loghandler) logger = LogAdapter(logger, "swift-bench-server") controller = BenchController(logger, conf) try: controller.run() except socket.error: logger.warning("Socket error", exc_info=1) logger.logger.removeHandler(loghandler) client_file.close() client.close() self.logger.info("...bench run completed; waiting for next run.")
def run(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.logger.info('Binding to %s:%s', self.bind_ip, self.bind_port) s.bind((self.bind_ip, self.bind_port)) s.listen(20) while True: client, address = s.accept() self.logger.debug('Accepting connection from %s:%s', *address) client_file = client.makefile('rb+', 1) json_data = client_file.read() conf = Values(json.loads(json_data)) self.logger.info( 'Starting run for %s:%s [put/get/del_concurrency: %s/%s/%s, ' 'num_objects: %s, num_gets: %s]', address[0], address[1], conf.put_concurrency, conf.get_concurrency, conf.del_concurrency, conf.num_objects, conf.num_gets) logger = logging.getLogger('bench-server') level = logging.DEBUG if conf.log_level.lower() == 'debug' \ else logging.INFO logger.setLevel(level) loghandler = logging.StreamHandler(client_file) logformat = logging.Formatter( '%(server)s %(asctime)s %(levelname)s %(message)s') loghandler.setFormatter(logformat) logger.addHandler(loghandler) logger = LogAdapter(logger, 'swift-bench-server') controller = BenchController(logger, conf) try: controller.run() except socket.error: logger.warning('Socket error', exc_info=1) logger.logger.removeHandler(loghandler) client_file.close() client.close() self.logger.info('...bench run completed; waiting for next run.')
def debug_logger(name='test'): """get a named adapted debug logger""" return LogAdapter(DebugLogger(), name)