当前位置: 首页>>代码示例>>Python>>正文


Python logging.root方法代码示例

本文整理汇总了Python中logging.root方法的典型用法代码示例。如果您正苦于以下问题:Python logging.root方法的具体用法?Python logging.root怎么用?Python logging.root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging的用法示例。


在下文中一共展示了logging.root方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_existing_loggers

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def _handle_existing_loggers(existing, child_loggers, disable_existing):
    """
    When (re)configuring logging, handle loggers which were in the previous
    configuration but are not in the new configuration. There's no point
    deleting them as other threads may continue to hold references to them;
    and by disabling them, you stop them doing any logging.

    However, don't disable children of named loggers, as that's probably not
    what was intended by the user. Also, allow existing loggers to NOT be
    disabled if disable_existing is false.
    """
    root = logging.root
    for log in existing:
        logger = root.manager.loggerDict[log]
        if log in child_loggers:
            logger.level = logging.NOTSET
            logger.handlers = []
            logger.propagate = True
        else:
            logger.disabled = disable_existing 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:config.py

示例2: common_logger_config

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def common_logger_config(self, logger, config, incremental=False):
        """
        Perform configuration which is common to root and non-root loggers.
        """
        level = config.get('level', None)
        if level is not None:
            logger.setLevel(logging._checkLevel(level))
        if not incremental:
            #Remove any existing handlers
            for h in logger.handlers[:]:
                logger.removeHandler(h)
            handlers = config.get('handlers', None)
            if handlers:
                self.add_handlers(logger, handlers)
            filters = config.get('filters', None)
            if filters:
                self.add_filters(logger, filters) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:19,代码来源:config.py

示例3: update_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def update_logger(self, logger: logging.Logger=None):
        if logger is None:
            logger = logging.root

        self._log_level = self.log_level if isinstance(self.log_level, int) else logging.getLevelName(self.log_level)

        if logger is logging.root:
            self._log_format = self.log_format.format(
                PEER_ID=self.peer_id[:8] if self.peer_id != "RadioStation" else self.peer_id,
                CHANNEL_NAME=self.channel_name
            )

            self._update_log_output_type()
            self._update_handlers(logger)

            if self.log_color:
                self._update_log_color_set(logger)
                for handler in logger.handlers:
                    if isinstance(handler, logging.StreamHandler):
                        handler.addFilter(self._root_stream_filter)
        else:
            logger.setLevel(self._log_level)

        if self.log_monitor:
            sender.setup('loopchain', host=self.log_monitor_host, port=self.log_monitor_port) 
开发者ID:icon-project,项目名称:loopchain,代码行数:27,代码来源:configuration.py

示例4: _test_log

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def _test_log(self, method, level=None):
        called = []
        support.patch(self, logging, 'basicConfig',
                      lambda *a, **kw: called.append((a, kw)))

        recording = RecordingHandler()
        logging.root.addHandler(recording)

        log_method = getattr(logging, method)
        if level is not None:
            log_method(level, "test me: %r", recording)
        else:
            log_method("test me: %r", recording)

        self.assertEqual(len(recording.records), 1)
        record = recording.records[0]
        self.assertEqual(record.getMessage(), "test me: %r" % recording)

        expected_level = level if level is not None else getattr(logging, method.upper())
        self.assertEqual(record.levelno, expected_level)

        # basicConfig was not called!
        self.assertEqual(called, []) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_logging.py

示例5: test_no_kwargs

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def test_no_kwargs(self):
        logging.basicConfig()

        # handler defaults to a StreamHandler to sys.stderr
        self.assertEqual(len(logging.root.handlers), 1)
        handler = logging.root.handlers[0]
        self.assertIsInstance(handler, logging.StreamHandler)
        self.assertEqual(handler.stream, sys.stderr)

        formatter = handler.formatter
        # format defaults to logging.BASIC_FORMAT
        self.assertEqual(formatter._style._fmt, logging.BASIC_FORMAT)
        # datefmt defaults to None
        self.assertIsNone(formatter.datefmt)
        # style defaults to %
        self.assertIsInstance(formatter._style, logging.PercentStyle)

        # level is not explicitly set
        self.assertEqual(logging.root.level, self.original_logging_level) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_logging.py

示例6: test_handlers

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def test_handlers(self):
        handlers = [
            logging.StreamHandler(),
            logging.StreamHandler(sys.stdout),
            logging.StreamHandler(),
        ]
        f = logging.Formatter()
        handlers[2].setFormatter(f)
        logging.basicConfig(handlers=handlers)
        self.assertIs(handlers[0], logging.root.handlers[0])
        self.assertIs(handlers[1], logging.root.handlers[1])
        self.assertIs(handlers[2], logging.root.handlers[2])
        self.assertIsNotNone(handlers[0].formatter)
        self.assertIsNotNone(handlers[1].formatter)
        self.assertIs(handlers[2].formatter, f)
        self.assertIs(handlers[0].formatter, handlers[1].formatter) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_logging.py

示例7: setUp

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def setUp(self):
        super(LoggerAdapterTest, self).setUp()
        old_handler_list = logging._handlerList[:]

        self.recording = RecordingHandler()
        self.logger = logging.root
        self.logger.addHandler(self.recording)
        self.addCleanup(self.logger.removeHandler, self.recording)
        self.addCleanup(self.recording.close)

        def cleanup():
            logging._handlerList[:] = old_handler_list

        self.addCleanup(cleanup)
        self.addCleanup(logging.shutdown)
        self.adapter = logging.LoggerAdapter(logger=self.logger, extra=None) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_logging.py

示例8: init_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def init_logging(self):
		logger = logging.getLogger("analysis")
		logger.setLevel(logging.DEBUG)

		#clean up any pre-existing handlers!
		handlers = [h for h in logger.handlers]
		for h in handlers:
			logger.removeHandler(h)

		#create console handler and set log level
		ch = logging.StreamHandler()
		ch.setLevel(logging.INFO)
		#create file handler and set log level

		#we overwrite old log files in each run.
		fh = logging.FileHandler(self.debug_log_filename, 'a')
		fh.setLevel(logging.DEBUG)

		#create file handler for the error log
		#each log file grows up to 1 megabyte, and we keep 4 old ones
		eh = logging.FileHandler(self.error_log_filename, 'a')
		eh.setLevel(logging.ERROR)

		#create formatter
		console_formatter = logging.Formatter("%(message)s")
		file_formatter = logging.Formatter("%(asctime)s - %(module)s(%(lineno)d) - %(message)s")

		#add formatter to ch and fh
		ch.setFormatter(console_formatter)
		fh.setFormatter(file_formatter)
		eh.setFormatter(file_formatter)
		#add ch and fh to logger
		logger.addHandler(ch)
		logger.addHandler(fh)
		logger.addHandler(eh)

		logging.root = logger 
开发者ID:carbonblack,项目名称:bit9platform,代码行数:39,代码来源:LastLine.py

示例9: configure_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def configure_logger(self, name, config, incremental=False):
        """Configure a non-root logger from a dictionary."""
        logger = logging.getLogger(name)
        self.common_logger_config(logger, config, incremental)
        propagate = config.get('propagate', None)
        if propagate is not None:
            logger.propagate = propagate 
开发者ID:war-and-code,项目名称:jawfish,代码行数:9,代码来源:config.py

示例10: configure_root

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def configure_root(self, config, incremental=False):
        """Configure a root logger from a dictionary."""
        root = logging.getLogger()
        self.common_logger_config(root, config, incremental) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:config.py

示例11: setup_experiment

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def setup_experiment(self):
    self.exp_out_root = self.out_root / self.experiment_name
    self.exp_out_root.mkdir(parents=True, exist_ok=True)

    if logging.root: del logging.root.handlers[:]
    logging.basicConfig(
      level=logging.INFO,
      handlers=[
        logging.FileHandler( str(self.exp_out_root / 'train.log') ),
        logging.StreamHandler()
      ],
      format='%(relativeCreated)d:%(levelname)s:%(process)d-%(processName)s: %(message)s'
    )

    logging.info('='*80)
    logging.info(f'Start of experiment: {self.experiment_name}')
    logging.info(socket.gethostname())
    self.log_datetime()
    logging.info('='*80)

    self.metric_path = self.exp_out_root / 'metrics.json'
    if self.metric_path.exists():
      with open(str(self.metric_path), 'r') as fp:
        self.metric_data = json.load(fp)
    else:
      self.metric_data = {}

    self.init_seed() 
开发者ID:autonomousvision,项目名称:connecting_the_dots,代码行数:30,代码来源:worker.py

示例12: get_net_path

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def get_net_path(self, epoch, root=None):
    if root is None:
      root = self.exp_out_root
    return root / f'net_{epoch:04d}.params' 
开发者ID:autonomousvision,项目名称:connecting_the_dots,代码行数:6,代码来源:worker.py

示例13: test_cli_entrypoint_no_arguments

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def test_cli_entrypoint_no_arguments(monkeypatch: Any, capsys: Any) -> None:
    cli = tomodachi.cli.CLI()
    monkeypatch.setattr(logging.root, 'handlers', [])

    with pytest.raises(SystemExit):
        tomodachi.cli.cli_entrypoint()

    out, err = capsys.readouterr()
    assert err == ''
    assert out == cli.help_command_usage() + "\n" 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:12,代码来源:test_cli.py

示例14: test_cli_entrypoint_print_help

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def test_cli_entrypoint_print_help(monkeypatch: Any, capsys: Any) -> None:
    cli = tomodachi.cli.CLI()
    monkeypatch.setattr(logging.root, 'handlers', [])

    with pytest.raises(SystemExit):
        tomodachi.cli.cli_entrypoint(['tomodachi', '-h'])

    out, err = capsys.readouterr()
    assert err == ''
    assert out == cli.help_command_usage() + "\n" 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:12,代码来源:test_cli.py

示例15: test_cli_entrypoint_print_dependency_versions

# 需要导入模块: import logging [as 别名]
# 或者: from logging import root [as 别名]
def test_cli_entrypoint_print_dependency_versions(monkeypatch: Any, capsys: Any) -> None:
    monkeypatch.setattr(logging.root, 'handlers', [])

    with pytest.raises(SystemExit):
        tomodachi.cli.cli_entrypoint(['tomodachi', '--dependency-versions'])

    out, err = capsys.readouterr()
    assert err == ''
    assert out != 'tomodachi/{}'.format(tomodachi.__version__) + "\n"

    import aiobotocore
    assert 'aiobotocore/{}'.format(aiobotocore.__version__) + "\n" in out 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:14,代码来源:test_cli.py


注:本文中的logging.root方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。