Python oslo_log.log.getLogger() Examples
The following are 30
code examples of oslo_log.log.getLogger().
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: test_log.py From oslo.log with Apache License 2.0 | 6 votes |
def test_rfc5424_isotime_format(self): self.config( logging_default_format_string="%(isotime)s %(message)s", logging_exception_prefix="%(isotime)s ", ) product_name = 'somename' exc_log = log.getLogger(product_name) self._add_handler_with_cleanup(exc_log) excepthook = log._create_logging_excepthook(product_name) message = 'Some error happened' try: raise Exception(message) except Exception: excepthook(*sys.exc_info()) expected_string = ("2015-12-16T13:54:26.517893+00:00 " "Exception: %s" % message) self.assertIn(expected_string, self.stream.getvalue())
Example #2
Source File: app.py From sgx-kms with Apache License 2.0 | 6 votes |
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 #3
Source File: api.py From masakari with Apache License 2.0 | 6 votes |
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 #4
Source File: worker.py From sgx-kms with Apache License 2.0 | 6 votes |
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 #5
Source File: retry_scheduler.py From sgx-kms with Apache License 2.0 | 6 votes |
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 #6
Source File: api.py From masakari with Apache License 2.0 | 6 votes |
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 #7
Source File: test_lib_single_svm.py From manila with Apache License 2.0 | 6 votes |
def setUp(self): super(NetAppFileStorageLibraryTestCase, self).setUp() self.mock_object(na_utils, 'validate_driver_instantiation') # Mock loggers as themselves to allow logger arg validation mock_logger = log.getLogger('mock_logger') self.mock_object(lib_single_svm.LOG, 'info', mock.Mock(side_effect=mock_logger.info)) config = fake.get_config_cmode() config.netapp_vserver = fake.VSERVER1 kwargs = { 'configuration': config, 'private_storage': mock.Mock(), 'app_version': fake.APP_VERSION } self.library = lib_single_svm.NetAppCmodeSingleSVMFileStorageLibrary( fake.DRIVER_NAME, **kwargs) self.library._client = mock.Mock() self.client = self.library._client
Example #8
Source File: wsgi.py From searchlight with Apache License 2.0 | 6 votes |
def __init__(self, threads=1000, workers=0): os.umask(0o27) # ensure files are created with the correct privileges self._logger = logging.getLogger("eventlet.wsgi.server") self._wsgi_logger = loggers.WritableLogger(self._logger) self.threads = threads self.children = set() self.stale_children = set() self.running = True self.pgid = os.getpid() self.workers = workers try: # NOTE(flaper87): Make sure this process # runs in its own process group. os.setpgid(self.pgid, self.pgid) except OSError: # NOTE(flaper87): When running searchlight-control, # (searchlight's functional tests, for example) # setpgid fails with EPERM as searchlight-control # creates a fresh session, of which the newly # launched service becomes the leader (session # leaders may not change process groups) # # Running searchlight-api is safe and # shouldn't raise any error here. self.pgid = 0
Example #9
Source File: test_log.py From oslo.log with Apache License 2.0 | 6 votes |
def test_remove_logger(self): fake_handler = {'class': 'logging.StreamHandler'} fake_logger = {'level': 'WARN'} conf1 = {'root': {'handlers': 'fake'}, 'handlers': {'fake': fake_handler}, 'loggers': {'a.a': fake_logger}} conf2 = {'root': {'handlers': 'fake'}, 'handlers': {'fake': fake_handler}} stream = io.StringIO() with self.mutate_conf(conf1, conf2) as (loginis, confs): stream = self.set_root_stream() log = logging.getLogger("a.a") log.info("info") log.warn("warn") self.assertEqual("warn\n", stream.getvalue()) stream = self.set_root_stream() log.info("info") log.warn("warn") self.assertEqual("info\nwarn\n", stream.getvalue())
Example #10
Source File: worker.py From barbican with Apache License 2.0 | 6 votes |
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 #11
Source File: retry_scheduler.py From barbican with Apache License 2.0 | 6 votes |
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-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(), restart_method='mutate' ).wait() except RuntimeError as e: fail(1, e)
Example #12
Source File: test_log.py From oslo.log with Apache License 2.0 | 6 votes |
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 #13
Source File: log.py From cloudbase-init with Apache License 2.0 | 6 votes |
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 #14
Source File: base.py From senlin with Apache License 2.0 | 6 votes |
def setup_logging(self): # Assign default logs to self.LOG so we can still # assert on senlin logs. default_level = logging.INFO if os.environ.get('OS_DEBUG') in _TRUE_VALUES: default_level = logging.DEBUG self.LOG = self.useFixture( fixtures.FakeLogger(level=default_level, format=_LOG_FORMAT)) base_list = set([nlog.split('.')[0] for nlog in logging.getLogger().logger.manager.loggerDict]) for base in base_list: if base in TEST_DEFAULT_LOGLEVELS: self.useFixture(fixtures.FakeLogger( level=TEST_DEFAULT_LOGLEVELS[base], name=base, format=_LOG_FORMAT)) elif base != 'senlin': self.useFixture(fixtures.FakeLogger( name=base, format=_LOG_FORMAT))
Example #15
Source File: nova.py From karbor with Apache License 2.0 | 6 votes |
def create(context, conf, **kwargs): conf.register_opts(nova_client_opts, group=CONFIG_GROUP) client_config = conf[CONFIG_GROUP] url = utils.get_url(SERVICE, context, client_config, append_project_fmt='%(url)s/%(project)s', **kwargs) LOG.debug('Creating nova client with url %s.', url) extensions = nc.discover_extensions(NOVACLIENT_VERSION) session = kwargs.get('session') if session is None: LOG.error('Creating nova client failed with url %s.', url) raise exception.InvalidParameterValue( err="The parameter session is None.") return nc.Client(NOVACLIENT_VERSION, extensions=extensions, session=kwargs.get('session'), endpoint_override=url, logger=log.getLogger('novaclient'))
Example #16
Source File: test_log.py From oslo.log with Apache License 2.0 | 6 votes |
def test_excepthook_logs_exception(self): product_name = 'somename' exc_log = log.getLogger(product_name) self._add_handler_with_cleanup(exc_log) excepthook = log._create_logging_excepthook(product_name) try: raise Exception('Some error happened') except Exception: excepthook(*sys.exc_info()) expected_string = ("CRITICAL somename [-] Unhandled error: " "Exception: Some error happened") self.assertIn(expected_string, self.stream.getvalue(), message="Exception is not logged")
Example #17
Source File: api.py From monasca-log-api with Apache License 2.0 | 6 votes |
def error_trap(app_name): """Decorator trapping any error during application boot time""" @six.wraps(error_trap) def _wrapper(func): @six.wraps(_wrapper) def _inner_wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception: logger = log.getLogger(__name__) logger.exception('Failed to load application \'%s\'', app_name) raise return _inner_wrapper return _wrapper
Example #18
Source File: notifiers.py From monasca-notification with Apache License 2.0 | 5 votes |
def load_plugins(): global possible_notifiers for plugin_class in CONF.notification_types.enabled: try: plugin_class = plugin_class.replace(':', '.') clz = importutils.import_class(plugin_class) possible_notifiers.append(clz(logging.getLogger(plugin_class))) except Exception: log.exception("unable to load the class %s , ignoring it" % plugin_class)
Example #19
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def test_remove_handler(self): fake_handler = {'class': 'logging.StreamHandler', 'args': ()} conf1 = {'root': {'handlers': 'fake'}, 'handlers': {'fake': fake_handler}} conf2 = {'root': {'handlers': ''}} with self.mutate_conf(conf1, conf2) as (loginis, confs): stream = self.set_root_stream() root = logging.getLogger() root.error("boo") self.assertEqual("boo\n", stream.getvalue()) stream.truncate(0) root.error("boo") self.assertEqual("", stream.getvalue())
Example #20
Source File: service.py From monasca-log-api with Apache License 2.0 | 5 votes |
def __init__(self): self._log = log.getLogger('service.LogCreator') self._log.info('Initializing LogCreator')
Example #21
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
def _setup_task_process(mp_log_q): # Setting up logging and cfg, needed since this is a new process cfg.CONF(sys.argv[1:], project='coriolis', version="1.0.0") utils.setup_logging() # Log events need to be handled in the parent process log_root = logging.getLogger(None).logger for handler in log_root.handlers: log_root.removeHandler(handler) log_root.addHandler(handlers.QueueHandler(mp_log_q))
Example #22
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
def _handle_mp_log_events(self, p, mp_log_q): while True: try: record = mp_log_q.get(timeout=1) if record is None: break logger = logging.getLogger(record.name).logger logger.handle(record) except queue.Empty: if not p.is_alive(): break
Example #23
Source File: workers.py From vitrage with Apache License 2.0 | 5 votes |
def run(self): global LOG if not LOG: LOG = log.getLogger(__name__) super(GraphCloneWorkerBase, self).run() self._entity_graph.notifier._subscriptions = [] # Quick n dirty self._init_instance() if self._entity_graph.num_vertices(): LOG.info("%s - Started %s (%s vertices)", self.__class__.__name__, self.worker_id, self._entity_graph.num_vertices()) else: LOG.info("%s - Started empty %s", self.__class__.__name__, self.worker_id) self._read_queue()
Example #24
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def setUp(self): super(FancyRecordTestCase, self).setUp() # NOTE(sdague): use the different formatters to demonstrate format # string with valid fancy keys and without. Slightly hacky, but given # the way log objects layer up seemed to be most concise approach self.config(logging_context_format_string="%(color)s " "[%(request_id)s]: " "%(instance)s" "%(resource)s" "%(message)s", logging_default_format_string="%(missing)s: %(message)s") self.colorlog = log.getLogger() self._add_handler_with_cleanup(self.colorlog, handlers.ColorHandler) self._set_log_level_with_cleanup(self.colorlog, logging.DEBUG)
Example #25
Source File: version.py From masakari with Apache License 2.0 | 5 votes |
def _load_config(): # Don't load in global context, since we can't assume # these modules are accessible when distutils uses # this module from six.moves import configparser from oslo_config import cfg from oslo_log import log as logging global loaded, MASAKARI_VENDOR, MASAKARI_PRODUCT, MASAKARI_PACKAGE if loaded: return loaded = True cfgfile = cfg.CONF.find_file("release") if cfgfile is None: return try: cfg = configparser.RawConfigParser() cfg.read(cfgfile) if cfg.has_option("Masakari", "vendor"): MASAKARI_VENDOR = cfg.get("Masakari", "vendor") if cfg.has_option("Masakari", "product"): MASAKARI_PRODUCT = cfg.get("Masakari", "product") if cfg.has_option("Masakari", "package"): MASAKARI_PACKAGE = cfg.get("Masakari", "package") except Exception as ex: LOG = logging.getLogger(__name__) LOG.error("Failed to load %(cfgfile)s: %(ex)s", {'cfgfile': cfgfile, 'ex': ex})
Example #26
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def setUp(self): super(InstanceRecordTestCase, self).setUp() self.config(logging_context_format_string="[%(request_id)s]: " "%(instance)s" "%(resource)s" "%(message)s", logging_default_format_string="%(instance)s" "%(resource)s" "%(message)s") self.log = log.getLogger() self._add_handler_with_cleanup(self.log) self._set_log_level_with_cleanup(self.log, logging.DEBUG)
Example #27
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def setUp(self): super(TraceLevelTestCase, self).setUp() self.config(logging_context_format_string="%(message)s") self.mylog = log.getLogger() self._add_handler_with_cleanup(self.mylog) self._set_log_level_with_cleanup(self.mylog, log.TRACE)
Example #28
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def test_oslo_dot(self): logger_name = 'oslo.subname' logger = log.getLogger(logger_name) self.assertEqual(logger_name, logger.logger.name)
Example #29
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def test_debug(self): paths = self.setup_confs( "[DEFAULT]\ndebug = false\n", "[DEFAULT]\ndebug = true\n") log_root = log.getLogger(None).logger log._setup_logging_from_conf(self.CONF, 'test', 'test') self.assertEqual(False, self.CONF.debug) self.assertEqual(log.INFO, log_root.getEffectiveLevel()) shutil.copy(paths[1], paths[0]) self.CONF.mutate_config_files() self.assertEqual(True, self.CONF.debug) self.assertEqual(log.DEBUG, log_root.getEffectiveLevel())
Example #30
Source File: test_log.py From oslo.log with Apache License 2.0 | 5 votes |
def set_root_stream(self): root = logging.getLogger() self.assertEqual(1, len(root.handlers)) handler = root.handlers[0] handler.stream = io.StringIO() return handler.stream