Python oslo_log.log.setup() Examples

The following are 30 code examples of oslo_log.log.setup(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_log.log , or try the search function .
Example #1
Source File: worker.py    From barbican with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF
        CONF(sys.argv[1:], project='barbican',
             version=version.version_info.version_string)

        # Import and configure logging.
        log.setup(CONF, 'barbican')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker node...")

        # Queuing initialization
        queue.init(CONF)

        service.launch(
            CONF,
            server.TaskServer(),
            workers=CONF.queue.asynchronous_workers,
            restart_method='mutate'
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #2
Source File: log.py    From cloudbase-init with Apache License 2.0 6 votes vote down vote up
def setup(product_name):
    log.setup(CONF, product_name)

    if CONF.logging_serial_port_settings:
        try:
            serialportlog = SerialPortHandler()
            log_root = log.getLogger(product_name).logger
            log_root.addHandler(serialportlog)

            datefmt = CONF.log_date_format
            serialportlog.setFormatter(
                formatters.ContextFormatter(project=product_name,
                                            datefmt=datefmt))
        except serial.SerialException:
            LOG.warn("Serial port: {0} could not be opened".format(
                     CONF.logging_serial_port_settings)) 
Example #3
Source File: api.py    From masakari with Apache License 2.0 6 votes vote down vote up
def main():
    api_config.parse_args(sys.argv)
    logging.setup(CONF, "masakari")
    log = logging.getLogger(__name__)
    objects.register_all()

    launcher = service.process_launcher()
    try:
        server = service.WSGIService("masakari_api", use_ssl=CONF.use_ssl)
        launcher.launch_service(server, workers=server.workers or 1)
    except exception.PasteAppNotFound as ex:
        log.error("Failed to start ``masakari_api`` service. Error: %s",
                  six.text_type(ex))
        sys.exit(1)

    launcher.wait() 
Example #4
Source File: api.py    From masakari with Apache License 2.0 6 votes vote down vote up
def initialize_application():
    conf_files = _get_config_files()
    api_config.parse_args([], default_config_files=conf_files)
    logging.setup(CONF, "masakari")

    objects.register_all()
    CONF(sys.argv[1:], project='masakari', version=version.version_string())

    # NOTE: Dump conf at debug (log_options option comes from oslo.service)
    # This is gross but we don't have a public hook into oslo.service to
    # register these options, so we are doing it manually for now;
    # remove this when we have a hook method into oslo.service.
    CONF.register_opts(service_opts.service_opts)
    if CONF.log_options:
        CONF.log_opt_values(logging.getLogger(__name__), logging.DEBUG)

    config.set_middleware_defaults()
    rpc.init(CONF)
    conf = conf_files[0]

    return deploy.loadapp('config:%s' % conf, name="masakari_api") 
Example #5
Source File: app.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def main_app(func):
    def _wrapper(global_config, **local_conf):
        # Queuing initialization
        queue.init(CONF, is_server_side=False)

        # Configure oslo logging and configuration services.
        log.setup(CONF, 'barbican')

        config.setup_remote_pydev_debug()

        # Initializing the database engine and session factory before the app
        # starts ensures we don't lose requests due to lazy initialization of
        # db connections.
        repositories.setup_database_engine_and_factory()

        wsgi_app = func(global_config, **local_conf)

        if newrelic_loaded:
            wsgi_app = newrelic.agent.WSGIApplicationWrapper(wsgi_app)
        LOG = log.getLogger(__name__)
        LOG.info(u._LI('Barbican app created and initialized'))
        return wsgi_app
    return _wrapper 
Example #6
Source File: worker.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF

        # Import and configure logging.
        log.setup(CONF, 'barbican')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker node...")

        # Queuing initialization
        queue.init(CONF)

        service.launch(
            CONF,
            server.TaskServer(),
            workers=CONF.queue.asynchronous_workers
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #7
Source File: retry_scheduler.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF

        # Import and configure logging.
        log.setup(CONF, 'barbican-retry-scheduler')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker retry/scheduler node...")

        # Queuing initialization (as a client only).
        queue.init(CONF, is_server_side=False)

        service.launch(
            CONF,
            retry_scheduler.PeriodicServer()
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #8
Source File: masakari_config.py    From masakari with Apache License 2.0 6 votes vote down vote up
def _log_setup(self):

        CONF = cfg.CONF

        self.set_request_context()

        DOMAIN = "masakari"
        CONF.log_file = self.conf_log.get("log_file")
        CONF.use_stderr = False

        logging.register_options(CONF)
        logging.setup(CONF, DOMAIN)

        log_dir = os.path.dirname(self.conf_log.get("log_file"))

        # create log dir if not created
        try:
            os.makedirs(log_dir)
        except OSError as exc:
            if exc.errno == errno.EEXIST and os.path.isdir(log_dir):
                pass
            else:
                raise

        return 
Example #9
Source File: wsgi.py    From designate with Apache License 2.0 6 votes vote down vote up
def init_application():
    conf_files = _get_config_files()
    logging.register_options(cfg.CONF)
    cfg.CONF([], project='designate', default_config_files=conf_files)
    config.set_defaults()
    logging.setup(cfg.CONF, 'designate')

    policy.init()

    if not rpc.initialized():
        rpc.init(CONF)

    heartbeat = heartbeat_emitter.get_heartbeat_emitter('api')
    heartbeat.start()

    conf = conf_files[0]

    return deploy.loadapp('config:%s' % conf, name='osapi_dns') 
Example #10
Source File: test_log.py    From oslo.log with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(LogLevelTestCase, self).setUp()
        levels = self.CONF.default_log_levels
        info_level = 'nova-test'
        warn_level = 'nova-not-debug'
        other_level = 'nova-below-debug'
        trace_level = 'nova-trace'
        levels.append(info_level + '=INFO')
        levels.append(warn_level + '=WARN')
        levels.append(other_level + '=7')
        levels.append(trace_level + '=TRACE')
        self.config(default_log_levels=levels)
        log.setup(self.CONF, 'testing')
        self.log = log.getLogger(info_level)
        self.log_no_debug = log.getLogger(warn_level)
        self.log_below_debug = log.getLogger(other_level)
        self.log_trace = log.getLogger(trace_level) 
Example #11
Source File: api.py    From searchlight with Apache License 2.0 6 votes vote down vote up
def configure_wsgi():
    # NOTE(hberaud): Call reset to ensure the ConfigOpts object doesn't
    # already contain registered options if the app is reloaded.
    CONF.reset()
    config.parse_args()
    config.set_config_defaults()
    logging.setup(CONF, 'searchlight')
    gmr.TextGuruMeditation.setup_autorun(version)
    utils.register_plugin_opts()

    # Fail fast if service policy files aren't found
    service_policies.check_policy_files()

    if CONF.profiler.enabled:
        _notifier = osprofiler.notifier.create("Messaging",
                                               notifier.messaging, {},
                                               notifier.get_transport(),
                                               "searchlight", "search",
                                               CONF.api.bind_host)
        osprofiler.notifier.set(_notifier)
    else:
        osprofiler.web.disable() 
Example #12
Source File: share.py    From manila with Apache License 2.0 6 votes vote down vote up
def main():
    log.register_options(CONF)
    gmr_opts.set_defaults(CONF)
    CONF(sys.argv[1:], project='manila',
         version=version.version_string())
    log.setup(CONF, "manila")
    utils.monkey_patch()
    gmr.TextGuruMeditation.setup_autorun(version, conf=CONF)
    launcher = service.process_launcher()
    if CONF.enabled_share_backends:
        for backend in CONF.enabled_share_backends:
            host = "%s@%s" % (CONF.host, backend)
            server = service.Service.create(host=host,
                                            service_name=backend,
                                            binary='manila-share',
                                            coordination=True)
            launcher.launch_service(server)
    else:
        server = service.Service.create(binary='manila-share')
        launcher.launch_service(server)
    launcher.wait() 
Example #13
Source File: conductor_server.py    From tacker with Apache License 2.0 5 votes vote down vote up
def main(manager='tacker.conductor.conductor_server.Conductor'):
    init(sys.argv[1:])
    objects.register_all()
    logging.setup(CONF, "tacker")
    oslo_messaging.set_transport_defaults(control_exchange='tacker')
    logging.setup(CONF, "tacker")
    CONF.log_opt_values(LOG, logging.DEBUG)
    server = tacker_service.Service.create(
        binary='tacker-conductor',
        topic=topics.TOPIC_CONDUCTOR,
        manager=manager)
    service.launch(CONF, server, restart_method='mutate').wait() 
Example #14
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def _config(self):
        os_level, log_path = tempfile.mkstemp()
        log_dir_path = os.path.dirname(log_path)
        log_file_path = os.path.basename(log_path)
        self.CONF(['--log-dir', log_dir_path, '--log-file', log_file_path])
        self.config(use_stderr=False)
        self.config(watch_log_file=True)
        log.setup(self.CONF, 'test', 'test')
        return log_path 
Example #15
Source File: bifrost_inventory.py    From bifrost with Apache License 2.0 5 votes vote down vote up
def _parse_config():
    config = cfg.ConfigOpts()
    log.register_options(config)
    config.register_cli_opts(opts)
    config(prog='bifrost_inventory.py')
    log.set_defaults()
    log.setup(config, "bifrost_inventory.py")
    return config 
Example #16
Source File: service.py    From watcher with Apache License 2.0 5 votes vote down vote up
def prepare_service(argv=(), conf=cfg.CONF):
    log.register_options(conf)
    gmr_opts.set_defaults(conf)

    config.parse_args(argv)
    cfg.set_defaults(_options.log_opts,
                     default_log_levels=_DEFAULT_LOG_LEVELS)
    log.setup(conf, 'python-watcher')
    conf.log_opt_values(LOG, log.DEBUG)
    objects.register_all()

    gmr.TextGuruMeditation.register_section(
        _('Plugins'), plugins_conf.show_plugins)
    gmr.TextGuruMeditation.setup_autorun(version, conf=conf) 
Example #17
Source File: inventory.py    From bifrost with Apache License 2.0 5 votes vote down vote up
def _parse_config():
    config = cfg.ConfigOpts()
    log.register_options(config)
    config.register_cli_opts(opts)
    config(prog='bifrost_inventory.py')
    log.set_defaults()
    log.setup(config, "bifrost_inventory.py")
    return config 
Example #18
Source File: config.py    From tacker with Apache License 2.0 5 votes vote down vote up
def setup_logging(conf):
    """Sets up the logging options for a log with supplied name.

    :param conf: a cfg.ConfOpts object
    """
    product_name = "tacker"
    logging.setup(conf, product_name)
    LOG.info("Logging enabled!") 
Example #19
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_log_config_append_unreadable(self):
        os.chmod(self.log_config_append, 0)
        self.config(log_config_append=self.log_config_append)
        self.assertRaises(log.LogConfigError, log.setup,
                          self.CONF,
                          'test_log_config_append') 
Example #20
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_log_config_append_invalid(self):
        names = self.create_tempfiles([('logging', 'squawk')])
        self.log_config_append = names[0]
        self.config(log_config_append=self.log_config_append)
        self.assertRaises(log.LogConfigError, log.setup,
                          self.CONF,
                          'test_log_config_append') 
Example #21
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_will_be_debug_if_debug_flag_set(self):
        self.config(debug=True)
        logger_name = 'test_is_debug'
        log.setup(self.CONF, logger_name)
        logger = logging.getLogger(logger_name)
        self.assertEqual(logging.DEBUG, logger.getEffectiveLevel()) 
Example #22
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_log_config_append_not_exist(self):
        os.remove(self.log_config_append)
        self.config(log_config_append=self.log_config_append)
        self.assertRaises(log.LogConfigError, log.setup,
                          self.CONF,
                          'test_log_config_append') 
Example #23
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def mutate_conf(self, conf1, conf2):
        loginis = self.create_tempfiles([
            ('log1.ini', self.mk_log_config(conf1)),
            ('log2.ini', self.mk_log_config(conf2))])
        confs = self.setup_confs(
            "[DEFAULT]\nlog_config_append = %s\n" % loginis[0],
            "[DEFAULT]\nlog_config_append = %s\n" % loginis[1])
        log.setup(self.CONF, '')

        yield loginis, confs
        shutil.copy(confs[1], confs[0])
        # prevent the mtime ever matching
        os.utime(self.CONF.log_config_append, (0, 0))
        self.CONF.mutate_config_files() 
Example #24
Source File: scheduler.py    From manila with Apache License 2.0 5 votes vote down vote up
def main():
    log.register_options(CONF)
    gmr_opts.set_defaults(CONF)
    CONF(sys.argv[1:], project='manila',
         version=version.version_string())
    log.setup(CONF, "manila")
    utils.monkey_patch()
    gmr.TextGuruMeditation.setup_autorun(version, conf=CONF)
    server = service.Service.create(binary='manila-scheduler',
                                    coordination=True)
    service.serve(server)
    service.wait() 
Example #25
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_will_be_info_if_debug_flag_not_set(self):
        self.config(debug=False)
        logger_name = 'test_is_not_debug'
        log.setup(self.CONF, logger_name)
        logger = logging.getLogger(logger_name)
        self.assertEqual(logging.INFO, logger.getEffectiveLevel()) 
Example #26
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(BaseTestCase, self).setUp()
        self.context_fixture = self.useFixture(
            fixture_context.ClearRequestContext())
        self.config_fixture = self.useFixture(
            fixture_config.Config(cfg.ConfigOpts()))
        self.config = self.config_fixture.config
        self.CONF = self.config_fixture.conf
        log.register_options(self.CONF)
        log.setup(self.CONF, 'base') 
Example #27
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(OSJournalHandlerTestCase, self).setUp()
        self.config(use_journal=True)
        self.journal = mock.patch("oslo_log.handlers.journal").start()
        self.addCleanup(self.journal.stop)
        log.setup(self.CONF, 'testing') 
Example #28
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_log_config_append_touch(self, mock_fileConfig):
        logini = self.create_tempfiles([('log.ini', MIN_LOG_INI)])[0]
        self.setup_confs("[DEFAULT]\nlog_config_append = %s\n" % logini)
        log.setup(self.CONF, '')
        mock_fileConfig.assert_called_once_with(
            logini, disable_existing_loggers=False)
        mock_fileConfig.reset_mock()

        # No thread sync going on here, just ensure the mtimes are different
        time.sleep(1)
        os.utime(logini, None)
        self.CONF.mutate_config_files()

        mock_fileConfig.assert_called_once_with(
            logini, disable_existing_loggers=False) 
Example #29
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_log_config_append_no_touch(self, mock_fileConfig):
        logini = self.create_tempfiles([('log.ini', MIN_LOG_INI)])[0]
        self.setup_confs("[DEFAULT]\nlog_config_append = %s\n" % logini)
        log.setup(self.CONF, '')
        mock_fileConfig.assert_called_once_with(
            logini, disable_existing_loggers=False)
        mock_fileConfig.reset_mock()

        self.CONF.mutate_config_files()

        self.assertFalse(mock_fileConfig.called) 
Example #30
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_log_config_append(self, mock_fileConfig):
        logini = self.create_tempfiles([('log.ini', MIN_LOG_INI)])[0]
        paths = self.setup_confs(
            "[DEFAULT]\nlog_config_append = no_exist\n",
            "[DEFAULT]\nlog_config_append = %s\n" % logini)
        self.assertRaises(log.LogConfigError, log.setup, self.CONF, '')
        self.assertFalse(mock_fileConfig.called)

        shutil.copy(paths[1], paths[0])
        self.CONF.mutate_config_files()

        mock_fileConfig.assert_called_once_with(
            logini, disable_existing_loggers=False)