本文整理汇总了Python中structlog.configure方法的典型用法代码示例。如果您正苦于以下问题:Python structlog.configure方法的具体用法?Python structlog.configure怎么用?Python structlog.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类structlog
的用法示例。
在下文中一共展示了structlog.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_logging
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def configure_logging():
"""Configure logging."""
logging.basicConfig(stream=sys.stderr, format="%(message)s", level=logging.CRITICAL)
logging.getLogger("greynoise").setLevel(logging.WARNING)
structlog.configure(
processors=[
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M.%S"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.dev.ConsoleRenderer(),
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
示例2: configure_logger
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def configure_logger(logger, level):
structlog.configure(
processors=[
structlog.stdlib.add_log_level,
structlog.stdlib.add_logger_name,
structlog.processors.format_exc_info,
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
logger_factory=structlog.stdlib.LoggerFactory(),
)
formatter = structlog.stdlib.ProcessorFormatter(
processor=structlog.dev.ConsoleRenderer()
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(level)
示例3: __config_logger__
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def __config_logger__(self):
logging.basicConfig(
level=logging.INFO, format=self.log_format, stream=sys.stdout,
)
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
)
return structlog.get_logger("Startup")
示例4: blockstore
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def blockstore(request, backend_store):
# TODO: allow to test against swift ?
if backend_store.startswith("postgresql://"):
config = PostgreSQLBlockStoreConfig()
else:
config = MockedBlockStoreConfig()
# More or less a hack to be able to to configure this fixture from
# the test function by adding tags to it
if request.node.get_closest_marker("raid0_blockstore"):
config = RAID0BlockStoreConfig(blockstores=[config, MockedBlockStoreConfig()])
if request.node.get_closest_marker("raid1_blockstore"):
config = RAID1BlockStoreConfig(blockstores=[config, MockedBlockStoreConfig()])
if request.node.get_closest_marker("raid5_blockstore"):
config = RAID5BlockStoreConfig(
blockstores=[config, MockedBlockStoreConfig(), MockedBlockStoreConfig()]
)
return config
示例5: _configure_logger
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def _configure_logger(logger_factory=None, wrapper_class=None):
if not logger_factory:
logger_factory = structlog.stdlib.LoggerFactory()
if not wrapper_class:
wrapper_class = structlog.stdlib.BoundLogger
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
add_request_ids_from_environment,
structlog.stdlib.add_log_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(sort_keys=True),
],
context_class=WRAPPED_DICT_CLASS,
logger_factory=logger_factory,
wrapper_class=wrapper_class,
cache_logger_on_first_use=True,
)
示例6: configure_logging
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def configure_logging(app):
processors = [
structlog.stdlib.filter_by_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
]
# send to mozdef before formatting into a string
if app.config.get('MOZDEF_TARGET'):
processors.append(mozdef_sender(app.config['MOZDEF_TARGET']))
processors.append(UnstructuredRenderer())
structlog.configure(
context_class=structlog.threadlocal.wrap_dict(dict),
processors=processors,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
示例7: configure
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def configure(profiles=None, docker_url=None):
global IS_CONFIGURED, PROFILES, DOCKER_URL
IS_CONFIGURED = True
if isinstance(profiles, dict):
profiles_map = {name: Profile(name, **profile_kwargs)
for name, profile_kwargs in profiles.items()}
else:
profiles_map = {profile.name: profile for profile in profiles or []}
PROFILES.update(profiles_map)
DOCKER_URL = docker_url
# structlog.is_configured() was added in 18.1
示例8: get_logger
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def get_logger():
global _logger
with _mutex:
if _logger is not None:
return _logger
structlog.configure(
processors=[
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
logger_factory=structlog.stdlib.LoggerFactory(),
)
own_logger = _get_library_logger()
if not logging.getLogger().handlers:
# own hander is set only when python root logger is not setup
formatter = structlog.stdlib.ProcessorFormatter(
processor=structlog.dev.ConsoleRenderer(colors=False),
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
own_logger.addHandler(handler)
own_logger.setLevel(logging.INFO)
_logger = structlog.get_logger(__name__)
return _logger
示例9: setup_structlog
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def setup_structlog():
structlog.configure(
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
)
logging.basicConfig(format='%(message)s')
示例10: test_structlog_processor
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def test_structlog_processor(self):
try:
# Use ReturnLogger for testing
structlog.configure(
processors=[tasktiger_processor],
context_class=dict,
logger_factory=structlog.ReturnLoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
# Run a simple task. Logging output is verified in
# the task.
self.tiger.delay(logging_task)
queues = self._ensure_queues(queued={"default": 1})
task = queues["queued"]["default"][0]
assert task["func"] == "tests.test_logging:logging_task"
Worker(self.tiger).run(once=True)
self._ensure_queues(queued={"default": 0})
assert not self.conn.exists("t:task:%s" % task["id"])
finally:
structlog.configure(
processors=[
structlog.stdlib.add_log_level,
structlog.stdlib.filter_by_level,
structlog.processors.TimeStamper(fmt="iso", utc=True),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
],
context_class=dict,
logger_factory=structlog.ReturnLoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
示例11: pytest_configure
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def pytest_configure(config):
# Patch pytest-trio
patch_pytest_trio()
# Configure structlog to redirect everything in logging
structlog.configure(
logger_factory=structlog.stdlib.LoggerFactory(),
processors=[
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S"),
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.dev.ConsoleRenderer(),
],
)
# Lock configuration
structlog.configure = lambda *args, **kwargs: None
# Add helper to caplog
patch_caplog()
if config.getoption("--run-postgresql-cluster"):
pgurl = bootstrap_postgresql_testbed()
capturemanager = config.pluginmanager.getplugin("capturemanager")
if capturemanager:
capturemanager.suspend(in_=True)
print(f"usage: PG_URL={pgurl} py.test --postgresql tests")
input("Press enter when you're done with...")
pytest.exit("bye")
elif config.getoption("--postgresql") and not is_xdist_master(config):
bootstrap_postgresql_testbed()
示例12: setup_logging
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def setup_logging(log_level: str, log_json: bool) -> None:
""" Basic structlog setup """
logging.basicConfig(level=log_level, stream=sys.stdout, format="%(message)s")
logging.getLogger("web3").setLevel("INFO")
logging.getLogger("urllib3").setLevel("INFO")
shared_processors = [
format_to_hex,
structlog.stdlib.add_log_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S.%f"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
]
if log_json:
processors = shared_processors + [structlog.processors.JSONRenderer()]
else:
processors = shared_processors + [structlog.dev.ConsoleRenderer()]
structlog.configure(
processors=processors,
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
示例13: setup_logging
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def setup_logging(log_config, instance_id,
verbosity_adjust=0, cache_on_use=True):
"""
Set up logging such that:
- The primary logging entry method is structlog
(see http://structlog.readthedocs.io/en/stable/index.html)
- Optionally cache the logger on first use
:return: structured logger
"""
def add_instance_id(_, __, event_dict):
event_dict['instance_id'] = instance_id
return event_dict
# Configure standard logging
logging.config.dictConfig(log_config)
logging.root.level -= 10 * verbosity_adjust
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
add_instance_id,
structlog.processors.UnicodeEncoder(),
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=cache_on_use,
)
# Mark first line of log
log = structlog.get_logger()
log.info("first-log-line, logging level %d" % logging.root.level)
return log
示例14: update_logging
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def update_logging(instance_id, vcore_id, cache_on_use=True):
"""
Add the vcore id to the structured logger
:param vcore_id: The assigned vcore id
:return: structured logger
"""
def add_instance_id(_, __, event_dict):
event_dict['instance_id'] = instance_id
return event_dict
def add_vcore_id(_, __, event_dict):
event_dict['vcore_id'] = vcore_id
return event_dict
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
add_instance_id,
add_vcore_id,
structlog.processors.UnicodeEncoder(),
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=cache_on_use,
)
# Mark first line of log
log = structlog.get_logger()
log.info("updated-logger")
return log
示例15: configure_logging
# 需要导入模块: import structlog [as 别名]
# 或者: from structlog import configure [as 别名]
def configure_logging(config):
structlog.configure(processors=processors,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True)
config.setdefault('logging', {})
config['logging'].setdefault('version', 1)
config['logging'].setdefault('handlers', {})
config['logging'].setdefault('formatters', {})
config['logging'].setdefault('loggers', {})
config['logging']['handlers'].setdefault('raw', {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'raw',
})
config['logging']['loggers'].setdefault('root', {
'handlers': ['raw'],
'level': 'DEBUG',
'propagate': False,
})
config['logging']['loggers'].setdefault('graphite_api', {
'handlers': ['raw'],
'level': 'DEBUG',
})
config['logging']['formatters']['raw'] = {'()': StructlogFormatter}
dictConfig(config['logging'])
if 'path' in config:
logger.info("loading configuration", path=config['path'])
else:
logger.info("loading default configuration")