import argparse import logging import coloredlogs from hugvey.central_command import CentralCommand if __name__ == '__main__': argParser = argparse.ArgumentParser( description='Start up a Hugvey Central Command. Ready to receive voices and other events, and eager to send commands') argParser.add_argument( '--config', '-c', required=True, type=str, help='The yaml config file to load' ) argParser.add_argument( '--verbose', '-v', action='count', default=0 ) argParser.add_argument( '--voyeur', action='store_true', help="Listen in on what is being said'." ) args = argParser.parse_args() # print(coloredlogs.DEFAULT_LOG_FORMAT) # exit() loglevel = logging.NOTSET if args.verbose > 1 else logging.DEBUG if args.verbose > 0 else logging.INFO coloredlogs.install( level=loglevel, # default: "%(asctime)s %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s" fmt="%(asctime)s %(hostname)s %(name)s[%(process)d,%(threadName)s] %(levelname)s %(message)s" ) rootLogger = logging.getLogger() logger = logging.getLogger("hugvey") logFileHandler = logging.handlers.RotatingFileHandler( './state/server.log', maxBytes=1024*5120, backupCount=5 ) logFileHandler.setFormatter(logging.Formatter( fmt="%(asctime)s %(name)s[%(process)d,%(threadName)s] %(levelname)s %(message)s" )) logFileHandler.setLevel(logging.DEBUG) # Buffer the writing to disk, to make it more efficient memBufferHandler = logging.handlers.MemoryHandler(200, flushLevel=logging.ERROR, target=logFileHandler, flushOnClose=True) rootLogger.addHandler(memBufferHandler) # logger.setLevel(1) # to send all records to cutelog socket_handler = logging.handlers.SocketHandler('127.0.0.1', 19996) # default listening address socket_handler.setLevel(logging.INFO) # OR should it be DEBUG? chaned to see difference in logging speed rootLogger.addHandler(socket_handler) logger.info("Start server") try: print('\33]0;Hugvey server\a', end='', flush=True) command = CentralCommand(args=args, debug_mode=args.verbose > 0) command.loadConfig(args.config) command.start() finally: # reset terminal title print('\33]0;\a', end='', flush=True)