# -*- coding: utf-8 -*-
from oslo_config import cfg
from oslo_context import context
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
DOMAIN = 'demo'
#在上述miniservice中,在REST的入口处,通过
#context.RequestContext()
#即生成了这样的request_id,之后每次log都会自动带上它。
def prepare():
#将配置文件中的信息注册到logging
logging.register_options(CONF)
#修改配置cfg文件的默认值,如'routes=INFO'
extra_log_level_defaults = [
'dogpile=INFO',
'routes=INFO'
]
logging.set_defaults(
default_log_levels=logging.get_default_log_levels() +
extra_log_level_defaults)
# Required setup based on configuration and domain
logging.setup(CONF, DOMAIN)
if __name__ == '__main__':
prepare()
LOG.info("Welcome to Oslo Logging")
LOG.error("Without context")
context.RequestContext(user='ddd',
tenant='dddd',
domain='a6b9dddd360e')
LOG.info("With context")