當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。