本文整理汇总了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
示例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)
示例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)
示例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, [])
示例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)
示例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)
示例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)
示例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
示例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
示例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)
示例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()
示例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'
示例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"
示例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"
示例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