Esempio n. 1
0
 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")
     levels.append("nova-not-debug=WARN")
     self.config = self.useFixture(config.Config()).config
     self.config(default_log_levels=levels, verbose=True)
     log.setup('testing')
     self.log = log.getLogger('nova-test')
     self.log_no_debug = log.getLogger('nova-not-debug')
Esempio n. 2
0
 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")
     levels.append("nova-not-debug=WARN")
     self.config = self.useFixture(config.Config()).config
     self.config(default_log_levels=levels,
                 verbose=True)
     log.setup('testing')
     self.log = log.getLogger('nova-test')
     self.log_no_debug = log.getLogger('nova-not-debug')
Esempio n. 3
0
def main():
    try:
        CONF = cfg.CONF
        # Register config options for the logging system
        log.register_options(CONF)
        # Init the config object
        CONF(project='glimpse', version='0.1')
        # Set some reasonable defaults
        config.set_defaults(CONF)
        # Load the logging options from config
        log.setup(CONF, 'glimpse')

        # Get our Logging instance
        LOG = log.getLogger(__name__)
        LOG.debug("Loading glimpse from %s" % CONF.config_file)
        # Spit our config out to stderr
        CONF.log_opt_values(LOG, logging.INFO)
        # Register eventlet poll, or select
        wsgi.set_eventlet_hub()
        # Init and start the WSGI server
        server = wsgi.Server()
        server.start(app, default_port=9292)
        server.wait()
    except (exception.WorkerCreationFailure, RuntimeError) as e:
        print("ERROR: %s\n" % exception.exception_to_str(e), file=sys.stderr)
        sys.exit(1)
Esempio n. 4
0
 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)
Esempio n. 5
0
    def start(self, application, default_port):
        """
        Run a WSGI server with the given application.

        :param application: The application to be run in the WSGI server
        :param default_port: Port to bind to if none is specified in conf
        """
        pgid = os.getpid()
        try:
            # NOTE(flaper87): Make sure this process
            # runs in its own process group.
            os.setpgid(pgid, pgid)
        except OSError:
            # NOTE(flaper87): When running glance-control,
            # (glance's functional tests, for example)
            # setpgid fails with EPERM as glance-control
            # creates a fresh session, of which the newly
            # launched service becomes the leader (session
            # leaders may not change process groups)
            #
            # Running glance-(api|registry) is safe and
            # shouldn't raise any error here.
            pgid = 0

        def kill_children(*args):
            """Kills the entire process group."""
            signal.signal(signal.SIGTERM, signal.SIG_IGN)
            signal.signal(signal.SIGINT, signal.SIG_IGN)
            self.running = False
            os.killpg(pgid, signal.SIGTERM)

        def hup(*args):
            """
            Shuts down the server, but allows running requests to complete
            """
            signal.signal(signal.SIGHUP, signal.SIG_IGN)
            self.running = False

        self.application = application
        self.sock = get_socket(default_port)

        os.umask(0o27)  # ensure files are created with the correct privileges
        self.logger = logging.getLogger('glance.wsgi.server')

        if CONF.workers == 0:
            # Useful for profiling, test, debug etc.
            self.pool = self.create_pool()
            self.pool.spawn_n(self._single_run, self.application, self.sock)
            return
        else:
            self.logger.info(_("Starting %d workers") % CONF.workers)
            signal.signal(signal.SIGTERM, kill_children)
            signal.signal(signal.SIGINT, kill_children)
            signal.signal(signal.SIGHUP, hup)
            while len(self.children) < CONF.workers:
                self.run_child()
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
    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")
Esempio n. 9
0
 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)
Esempio n. 10
0
 def test_child_log_has_level_of_parent_flag(self):
     l = log.getLogger('nova-test.foo')
     self.assertEqual(logging.AUDIT, l.logger.getEffectiveLevel())
Esempio n. 11
0
 def setUp(self):
     super(LoggerTestCase, self).setUp()
     self.log = log.getLogger(None)
Esempio n. 12
0
Includes decorator for re-raising Cue-type exceptions.

SHOULD include dedicated exception logging.

"""

from oslo.config import cfg
import six

from cue.common.i18n import _
from cue.common.i18n import _LE
from oslo.log import log as logging


LOG = logging.getLogger(__name__)

exc_log_opts = [
    cfg.BoolOpt('fatal_exception_format_errors',
                default=False,
                help='Make exception message format errors fatal.'),
]

CONF = cfg.CONF
CONF.register_opts(exc_log_opts)


def _cleanse_dict(original):
    """Strip all admin_password, new_pass, rescue_pass keys from a dict."""
    return dict((k, v) for k, v in original.iteritems() if "_pass" not in k)
Esempio n. 13
0
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         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.


from oslo.log.fixture import logging as logging_fixture
from oslo.log import log as logging
from oslotest import base as test_base

LOG = logging.getLogger(__name__)


class TestLoggingFixture(test_base.BaseTestCase):
    def test_logging_handle_error(self):
        LOG.info('pid of first child is %(foo)s', 1)
        self.useFixture(logging_fixture.get_logging_handle_error_fixture())
        self.assertRaises(TypeError,
                          LOG.info,
                          'pid of first child is %(foo)s',
                          1)