def setUp(self): super(MultiNotifierTestCase, self).setUp() self.config = self.useFixture(config.Config()).config self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs # Mock log to add one to exception_count when log.exception is called def mock_exception(cls, *args): self.exception_count += 1 self.exception_count = 0 notifier_log = log.getLogger( 'essential.notifier.api') self.stubs.Set(notifier_log, "exception", mock_exception) # Mock no_op notifier to add one to notify_count when called. def mock_notify(cls, *args): self.notify_count += 1 self.notify_count = 0 self.stubs.Set(no_op_notifier, 'notify', mock_notify) # Mock log_notifier to raise RuntimeError when called. def mock_notify2(cls, *args): raise RuntimeError("Bad notifier.") self.stubs.Set(log_notifier, 'notify', mock_notify2) self.addCleanup(notifier_api._reset_drivers)
def _run(self, application, socket): """Start a WSGI server in a new green thread.""" logger = logging.getLogger('eventlet.wsgi.server') eventlet.wsgi.server(socket, application, custom_pool=self.pool, log=logging.WritableLogger(logger))
def setUp(self): super(DomainTestCase, self).setUp() self.config = self.useFixture(config.Config()).config self.config(logging_context_format_string="[%(request_id)s]: " "%(user_identity)s " "%(message)s") self.mylog = log.getLogger() self._add_handler_with_cleanup(self.mylog) self._set_log_level_with_cleanup(self.mylog, logging.DEBUG)
def setUp(self): super(LogLevelTestCase, self).setUp() self.CONF = self.useFixture(config.Config()).conf levels = self.CONF.default_log_levels levels.append("nova-test=AUDIT") self.config = self.useFixture(config.Config()).config self.config(default_log_levels=levels, verbose=True) log.setup('testing') self.log = log.getLogger('nova-test')
def notify(_context, message): """Notifies the recipient of the desired event given the model. Log notifications using OpenStack's default logging system. """ priority = message.get('priority', CONF.default_notification_level) priority = priority.lower() logger = logging.getLogger('essential.notification.%s' % message['event_type']) getattr(logger, priority)(jsonutils.dumps(message))
def setUp(self): super(ContextFormatterTestCase, self).setUp() self.config = self.useFixture(config.Config()).config self.config(logging_context_format_string="HAS CONTEXT " "[%(request_id)s]: " "%(message)s", logging_default_format_string="NOCTXT: %(message)s", logging_debug_format_suffix="--DBG") self.log = log.getLogger('') # obtain root logger instead of 'unknown' self._add_handler_with_cleanup(self.log) self._set_log_level_with_cleanup(self.log, logging.DEBUG)
def setUp(self): super(FancyRecordTestCase, self).setUp() self.config = self.useFixture(config.Config()).config # 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" "%(message)s", logging_default_format_string="%(missing)s: %(message)s") self.colorlog = log.getLogger() self._add_handler_with_cleanup(self.colorlog, log.ColorHandler) self._set_log_level_with_cleanup(self.colorlog, logging.DEBUG)
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 [-] " "Exception: Some error happened") self.assertTrue(expected_string in self.stream.getvalue(), msg="Exception is not logged")
def test_error_notification(self): self.config(publish_errors=True, use_stderr=False) def mock_notify(context, message): msgs.append(message) msgs = [] self.stubs.Set(no_op_notifier, 'notify', mock_notify) LOG = log.getLogger('test_error_notification.common') log.setup('test_error_notification') LOG.error('foo') self.assertEqual(1, len(msgs)) msg = msgs[0] self.assertEqual(msg['event_type'], 'error_notification') self.assertEqual(msg['priority'], 'ERROR') self.assertEqual(msg['payload']['error'], 'foo')
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import socket import uuid from essential.config import cfg from essential import context from essential.gettextutils import _, _LE from essential import importutils from essential import jsonutils from essential import log as logging from essential import timeutils LOG = logging.getLogger(__name__) notifier_opts = [ cfg.MultiStrOpt('notification_driver', default=[], help='Driver or drivers to handle sending notifications'), cfg.StrOpt('default_notification_level', default='INFO', help='Default notification level for outgoing notifications'), cfg.StrOpt('default_publisher_id', default=None, help='Default publisher_id for outgoing notifications'), ] CONF = cfg.CONF CONF.register_opts(notifier_opts)
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import six from essential import log as logging from essential.scheduler import filters from essential.scheduler.filters import extra_specs_ops LOG = logging.getLogger(__name__) class CapabilitiesFilter(filters.BaseHostFilter): """HostFilter to work with resource (instance & volume) type records.""" def _satisfies_extra_specs(self, capabilities, resource_type): """Check that the capabilities provided by the services satisfy the extra specs associated with the resource type. """ extra_specs = resource_type.get('extra_specs', []) if not extra_specs: return True for key, req in six.iteritems(extra_specs): # Either not scope format, or in capabilities scope
def setUp(self): super(JSONFormatterTestCase, self).setUp() self.log = log.getLogger('test-json') self._add_handler_with_cleanup(self.log, formatter=log.JSONFormatter) self._set_log_level_with_cleanup(self.log, logging.DEBUG)
def test_child_log_has_level_of_parent_flag(self): l = log.getLogger('nova-test.foo') self.assertEqual(logging.AUDIT, l.logger.getEffectiveLevel())
def setUp(self): super(LoggerTestCase, self).setUp() self.log = log.getLogger(None)
def _run(self, application, socket): """Start a WSGI server in a new green thread.""" logger = logging.getLogger('eventlet.wsgi.server') eventlet.wsgi.server(socket, application, custom_pool=self.pool, log=logging.WritableLogger(logger))