コード例 #1
0
def configure_logging(conf):
    default_formatter = logging.Formatter(
        "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")

    file_handler = logging.handlers.RotatingFileHandler(conf.log_file_path,
                                                        maxBytes=2097152,
                                                        backupCount=5)
    file_handler.setFormatter(default_formatter)
    logging.getLogger('lbry').addHandler(file_handler)
    logging.getLogger('torba').addHandler(file_handler)

    handler = logging.StreamHandler()
    handler.setFormatter(default_formatter)

    log.addHandler(handler)
    logging.getLogger('lbry').addHandler(handler)
    logging.getLogger('torba').addHandler(handler)

    logging.getLogger('aioupnp').setLevel(logging.WARNING)
    logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
    logging.getLogger('lbry').setLevel(
        logging.DEBUG if lbrynet_android_utils.isDebug() else logging.INFO)
    logging.getLogger('torba').setLevel(logging.INFO)

    loggly_handler = get_loggly_handler()
    loggly_handler.setLevel(logging.ERROR)
    logging.getLogger('lbry').addHandler(loggly_handler)
コード例 #2
0
ファイル: cli.py プロジェクト: thebubbleindex/lbry-sdk
def setup_logging(logger: logging.Logger, args: argparse.Namespace,
                  conf: Config):
    default_formatter = logging.Formatter(
        "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
    file_handler = logging.handlers.RotatingFileHandler(conf.log_file_path,
                                                        maxBytes=2097152,
                                                        backupCount=5)
    file_handler.setFormatter(default_formatter)
    for module_name in LOG_MODULES:
        logger.getChild(module_name).addHandler(file_handler)
    if not args.quiet:
        handler = logging.StreamHandler()
        handler.setFormatter(default_formatter)
        for module_name in LOG_MODULES:
            logger.getChild(module_name).addHandler(handler)

    logger.getChild('lbry').setLevel(logging.INFO)
    logger.getChild('aioupnp').setLevel(logging.WARNING)
    logger.getChild('aiohttp').setLevel(logging.CRITICAL)

    if args.verbose is not None:
        if len(args.verbose) > 0:
            for module in args.verbose:
                logger.getChild(module).setLevel(logging.DEBUG)
        else:
            logger.getChild('lbry').setLevel(logging.DEBUG)

    loggly_handler = get_loggly_handler(conf)
    loggly_handler.setLevel(logging.ERROR)
    logger.getChild('lbry').addHandler(loggly_handler)
コード例 #3
0
def setup_logging(args: argparse.Namespace, conf: Config,
                  loop: asyncio.AbstractEventLoop):
    default_formatter = logging.Formatter(
        "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
    file_handler = logging.handlers.RotatingFileHandler(conf.log_file_path,
                                                        maxBytes=2097152,
                                                        backupCount=5)
    file_handler.setFormatter(default_formatter)
    log.addHandler(file_handler)
    logging.getLogger('torba').addHandler(file_handler)

    if not args.quiet:
        handler = logging.StreamHandler()
        handler.setFormatter(default_formatter)
        log.addHandler(handler)
        logging.getLogger('torba').addHandler(handler)
        logging.getLogger('torba').setLevel(logging.INFO)

    logging.getLogger('aioupnp').setLevel(logging.WARNING)
    logging.getLogger('aiohttp').setLevel(logging.CRITICAL)

    log.setLevel(logging.INFO)
    if args.verbose is not None:
        loop.set_debug(True)
        if len(args.verbose) > 0:
            for module in args.verbose:
                logging.getLogger(module).setLevel(logging.DEBUG)
        else:
            log.setLevel(logging.DEBUG)

    if conf.share_usage_data:
        loggly_handler = get_loggly_handler()
        loggly_handler.setLevel(logging.ERROR)
        log.addHandler(loggly_handler)
コード例 #4
0
def run_daemon(args: list, conf: Config):
    default_formatter = logging.Formatter(
        "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
    file_handler = logging.handlers.RotatingFileHandler(conf.log_file_path,
                                                        maxBytes=2097152,
                                                        backupCount=5)
    file_handler.setFormatter(default_formatter)
    log.addHandler(file_handler)
    logging.getLogger('torba').addHandler(file_handler)

    if not args.quiet:
        handler = logging.StreamHandler()
        handler.setFormatter(default_formatter)
        log.addHandler(handler)
        logging.getLogger('torba').addHandler(handler)
        logging.getLogger('torba').setLevel(logging.INFO)

    logging.getLogger('aioupnp').setLevel(logging.WARNING)
    logging.getLogger('aiohttp').setLevel(logging.CRITICAL)

    loop = asyncio.get_event_loop()

    if args.verbose:
        log.setLevel(logging.DEBUG)
        loop.set_debug(True)
    else:
        log.setLevel(logging.INFO)

    if conf.share_usage_data:
        loggly_handler = get_loggly_handler()
        loggly_handler.setLevel(logging.ERROR)
        log.addHandler(loggly_handler)

    daemon = Daemon(conf)

    def __exit():
        raise GracefulExit()

    try:
        loop.add_signal_handler(signal.SIGINT, __exit)
        loop.add_signal_handler(signal.SIGTERM, __exit)
    except NotImplementedError:
        pass  # Not implemented on Windows

    try:
        loop.run_until_complete(daemon.start())
        loop.run_forever()
    except (GracefulExit, KeyboardInterrupt, asyncio.CancelledError):
        pass
    finally:
        loop.run_until_complete(daemon.stop())

    if hasattr(loop, 'shutdown_asyncgens'):
        loop.run_until_complete(loop.shutdown_asyncgens())
コード例 #5
0
    async def test_settings(self):
        self.assertEqual(self.daemon.jsonrpc_settings_get()['lbryum_servers'][0], ('127.0.0.1', 50001))

        setting = self.daemon.jsonrpc_settings_set('lbryum_servers', ['server:50001'])
        self.assertEqual(setting['lbryum_servers'][0], ('server', 50001))
        self.assertEqual(self.daemon.jsonrpc_settings_get()['lbryum_servers'][0], ('server', 50001))

        setting = self.daemon.jsonrpc_settings_clear('lbryum_servers')
        self.assertEqual(setting['lbryum_servers'][0], ('spv11.lbry.com', 50001))
        self.assertEqual(self.daemon.jsonrpc_settings_get()['lbryum_servers'][0], ('spv11.lbry.com', 50001))

        # test_privacy_settings (merged for reducing test time, unmerge when its fast)
        # tests that changing share_usage_data propagates to the relevant properties
        self.assertFalse(self.daemon.jsonrpc_settings_get()['share_usage_data'])
        loggly = get_loggly_handler(self.daemon.conf)
        self.addCleanup(loggly.close)
        self.assertFalse(self.daemon.analytics_manager.enabled)
        self.assertFalse(loggly.enabled)
        self.daemon.jsonrpc_settings_set('share_usage_data', True)
        self.assertTrue(self.daemon.jsonrpc_settings_get()['share_usage_data'])
        self.assertTrue(self.daemon.analytics_manager.enabled)
        self.assertTrue(loggly.enabled)
        self.daemon.jsonrpc_settings_set('share_usage_data', False)
コード例 #6
0
ファイル: cli.py プロジェクト: shauser/lbry-sdk
def main(argv=None):
    argv = argv or sys.argv[1:]
    parser = get_argument_parser()
    args, command_args = parser.parse_known_args(argv)

    conf = Config.create_from_arguments(args)
    for directory in (conf.data_dir, conf.download_dir, conf.wallet_dir):
        ensure_directory_exists(directory)

    if args.cli_version:
        print(f"lbrynet {lbrynet_version}")
        return 0

    elif args.command == 'start':

        if args.help:
            args.start_parser.print_help()
            return 0

        default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
        file_handler = logging.handlers.RotatingFileHandler(
            conf.log_file_path, maxBytes=2097152, backupCount=5
        )
        file_handler.setFormatter(default_formatter)
        log.addHandler(file_handler)
        logging.getLogger('torba').addHandler(file_handler)

        if not args.quiet:
            handler = logging.StreamHandler()
            handler.setFormatter(default_formatter)
            log.addHandler(handler)
            logging.getLogger('torba').addHandler(handler)
            logging.getLogger('torba').setLevel(logging.INFO)

        logging.getLogger('aioupnp').setLevel(logging.WARNING)
        logging.getLogger('aiohttp').setLevel(logging.CRITICAL)

        loop = asyncio.get_event_loop()

        if args.verbose:
            log.setLevel(logging.DEBUG)
            loop.set_debug(True)
        else:
            log.setLevel(logging.INFO)

        if conf.share_usage_data:
            loggly_handler = get_loggly_handler()
            loggly_handler.setLevel(logging.ERROR)
            log.addHandler(loggly_handler)

        daemon = Daemon(conf)
        started = False
        def __exit():
            if started:
                daemon.stop_event.set()
            else:
                raise GracefulExit()
        try:
            loop.add_signal_handler(signal.SIGINT, __exit)
            loop.add_signal_handler(signal.SIGTERM, __exit)
        except NotImplementedError:
            pass  # Not implemented on Windows
        try:
            loop.run_until_complete(daemon.start())
            started = True
            loop.run_until_complete(daemon.stop_event.wait())
        except (GracefulExit, KeyboardInterrupt):
            pass
        finally:
            loop.run_until_complete(daemon.stop())
        if hasattr(loop, 'shutdown_asyncgens'):
            loop.run_until_complete(loop.shutdown_asyncgens())

    elif args.command is not None:

        doc = args.doc
        api_method_name = args.api_method_name
        if args.replaced_by:
            print(f"{args.api_method_name} is deprecated, using {args.replaced_by['api_method_name']}.")
            doc = args.replaced_by['doc']
            api_method_name = args.replaced_by['api_method_name']

        if args.help:
            print(doc)
        else:
            parsed = docopt(doc, command_args)
            params = set_kwargs(parsed)
            loop = asyncio.get_event_loop()
            loop.run_until_complete(execute_command(conf, api_method_name, params))

    elif args.group is not None:
        args.group_parser.print_help()

    else:
        parser.print_help()

    return 0