Exemple #1
0
async def get_logger(argv, **conf_options):
    # loggly requires loop, so we do this in async function

    logger = logging.getLogger('test-root-logger')
    temp_dir = tempfile.mkdtemp()
    temp_config = os.path.join(temp_dir, 'settings.yml')

    try:
        # create a config (to be loaded on startup)
        _conf = Config.create_from_arguments(
            SimpleNamespace(config=temp_config))
        with _conf.update_config():
            for opt_name, opt_value in conf_options.items():
                setattr(_conf, opt_name, opt_value)

        # do what happens on startup
        argv.extend(['--data-dir', temp_dir])
        argv.extend(['--wallet-dir', temp_dir])
        argv.extend(['--config', temp_config])
        parser = cli.get_argument_parser()
        args, command_args = parser.parse_known_args(argv)
        conf: Config = Config.create_from_arguments(args)
        setup_logging(logger, args, conf)
        yield logger

    finally:
        shutil.rmtree(temp_dir, ignore_errors=True)
        for mod in cli.LOG_MODULES:
            log = logger.getChild(mod)
            log.setLevel(logging.NOTSET)
            while log.handlers:
                h = log.handlers[0]
                log.removeHandler(log.handlers[0])
                h.close()
Exemple #2
0
 def setup(argv):
     parser = cli.get_argument_parser()
     args, command_args = parser.parse_known_args(argv)
     conf = Config.create_from_arguments(args)
     conf.data_dir = '/tmp'
     setup_logging(args, conf, logger)
Exemple #3
0
 def setup(argv):
     parser = cli.get_argument_parser()
     args, command_args = parser.parse_known_args(argv)
     loop = asyncio.get_event_loop()
     conf = Config.create_from_arguments(args)
     cli.setup_logging(args, conf, loop)