Refactor Keystone to use unified logging from Oslo

Modifications to use log from /keystone/openstack/common/log.py instead
of /keystone/common/logging.py. This change also includes some
refactoring to remove the WriteableLogger class from common/wsgi.py
since that is already included in the unified logging sync from Oslo.
This also moves fail_gracefully from /keystone/common/logging.py to
service.py as it is only used within that module.

blueprint unified-logging-in-keystone

Change-Id: I24b319bd6cfe5e345ea903196188f2394f4ef102
This commit is contained in:
Lance Bragstad 2013-08-12 17:41:40 +00:00 committed by Dolph Mathews
parent 14e090154c
commit 0c2fc69ba1
41 changed files with 71 additions and 76 deletions

View File

@ -23,11 +23,11 @@ from keystone import assignment
from keystone import clean
from keystone.common import dependency
from keystone.common import ldap as common_ldap
from keystone.common import logging
from keystone.common import models
from keystone import config
from keystone import exception
from keystone.identity.backends import ldap as ldap_identity
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -17,10 +17,10 @@
"""Main entry point into the assignment service."""
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -17,12 +17,12 @@
from keystone.common import controller
from keystone.common import dependency
from keystone.common import logging
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone import identity
from keystone.openstack.common import importutils
from keystone.openstack.common import log as logging
from keystone import token
from keystone import trust

View File

@ -15,9 +15,9 @@
# under the License.
from keystone import auth
from keystone.common import logging
from keystone import exception
from keystone import identity
from keystone.openstack.common import log as logging
METHOD_NAME = 'password'

View File

@ -15,9 +15,9 @@
# under the License.
from keystone import auth
from keystone.common import logging
from keystone.common import wsgi
from keystone import exception
from keystone.openstack.common import log as logging
from keystone import token

View File

@ -18,8 +18,8 @@ import os.path
from keystone.catalog.backends import kvs
from keystone.catalog import core
from keystone.common import logging
from keystone import config
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -18,10 +18,10 @@
"""Main entry point into the Catalog service."""
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -1,7 +1,7 @@
import hashlib
from keystone.common import environment
from keystone.common import logging
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -3,11 +3,10 @@ import functools
import uuid
from keystone.common import dependency
from keystone.common import logging
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)
CONF = config.CONF

View File

@ -2,7 +2,7 @@ import functools
import os
from keystone.common import config
from keystone.common import logging
from keystone.openstack.common import log as logging
CONF = config.CONF
LOG = logging.getLogger(__name__)

View File

@ -26,8 +26,7 @@ import eventlet
import eventlet.wsgi
import greenlet
from keystone.common import logging
from keystone.common import wsgi
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@ -108,7 +107,7 @@ class Server(object):
log = logging.getLogger('eventlet.wsgi.server')
try:
eventlet.wsgi.server(socket, application, custom_pool=self.pool,
log=wsgi.WritableLogger(log))
log=logging.WritableLogger(log))
except Exception:
LOG.exception(_('Server error'))
raise

View File

@ -20,9 +20,8 @@ import ldap
from ldap import filter as ldap_filter
from keystone.common.ldap import fakeldap
from keystone.common import logging
from keystone import exception
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@ -509,7 +508,7 @@ class LdapWrapper(object):
def add_s(self, dn, attrs):
ldap_attrs = [(kind, [py2ldap(x) for x in safe_iter(values)])
for kind, values in attrs]
if LOG.isEnabledFor(logging.DEBUG):
if LOG.isEnabledFor(LOG.debug):
sane_attrs = [(kind, values
if kind != 'userPassword'
else ['****'])
@ -519,7 +518,7 @@ class LdapWrapper(object):
return self.conn.add_s(dn, ldap_attrs)
def search_s(self, dn, scope, query, attrlist=None):
if LOG.isEnabledFor(logging.DEBUG):
if LOG.isEnabledFor(LOG.debug):
LOG.debug(_(
'LDAP search: dn=%(dn)s, scope=%(scope)s, query=%(query)s, '
'attrs=%(attrlist)s') % {
@ -586,7 +585,7 @@ class LdapWrapper(object):
else [py2ldap(x) for x in safe_iter(values)]))
for op, kind, values in modlist]
if LOG.isEnabledFor(logging.DEBUG):
if LOG.isEnabledFor(LOG.debug):
sane_modlist = [(op, kind, (values if kind != 'userPassword'
else ['****']))
for op, kind, values in ldap_modlist]

View File

@ -29,8 +29,8 @@ import shelve
import ldap
from keystone.common import logging
from keystone.common import utils
from keystone.openstack.common import log as logging
SCOPE_NAMES = {
@ -41,8 +41,6 @@ SCOPE_NAMES = {
LOG = logging.getLogger(__name__)
#Only enable a lower level than WARN if you are actively debugging
LOG.level = logging.WARN
def _match_query(query, attrs):

View File

@ -19,9 +19,8 @@ import os
import stat
from keystone.common import environment
from keystone.common import logging
from keystone import config
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)
CONF = config.CONF

View File

@ -26,10 +26,10 @@ from sqlalchemy.orm.attributes import InstrumentedAttribute
import sqlalchemy.pool
from sqlalchemy import types as sql_types
from keystone.common import logging
from keystone import config
from keystone import exception
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -21,10 +21,10 @@ from sqlalchemy import exc
from keystone.assignment.backends import sql as assignment_sql
from keystone.common import logging
from keystone import config
from keystone.contrib.ec2.backends import sql as ec2_sql
from keystone.identity.backends import sql as identity_sql
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -19,10 +19,10 @@
import uuid
from keystone import assignment
from keystone.common import logging
from keystone import config
from keystone.contrib.ec2.backends import sql as ec2_sql
from keystone import identity
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -27,8 +27,8 @@ import passlib.hash
from keystone.common import config
from keystone.common import environment
from keystone.common import logging
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -27,11 +27,11 @@ import webob.dec
import webob.exc
from keystone.common import config
from keystone.common import logging
from keystone.common import utils
from keystone import exception
from keystone.openstack.common import importutils
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log as logging
CONF = config.CONF
@ -122,17 +122,6 @@ def validate_token_bind(context, token_ref):
raise exception.Unauthorized()
class WritableLogger(object):
"""A thin wrapper that responds to `write` and logs."""
def __init__(self, logger, level=logging.DEBUG):
self.logger = logger
self.level = level
def write(self, msg):
self.logger.log(self.level, msg)
class Request(webob.Request):
pass
@ -394,7 +383,7 @@ class Debug(Middleware):
@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):
if LOG.isEnabledFor(logging.DEBUG):
if LOG.isEnabledFor(LOG.debug):
LOG.debug('%s %s %s', ('*' * 20), 'REQUEST ENVIRON', ('*' * 20))
for key, value in req.environ.items():
LOG.debug('%s = %s', key, mask_password(value,
@ -406,7 +395,7 @@ class Debug(Middleware):
LOG.debug('')
resp = req.get_response(self.application)
if LOG.isEnabledFor(logging.DEBUG):
if LOG.isEnabledFor(LOG.debug):
LOG.debug('%s %s %s', ('*' * 20), 'RESPONSE HEADERS', ('*' * 20))
for (key, value) in resp.headers.iteritems():
LOG.debug('%s = %s', key, value)
@ -455,7 +444,7 @@ class Router(object):
# if we're only running in debug, bump routes' internal logging up a
# notch, as it's very spammy
if CONF.debug:
logging.getLogger('routes.middleware').setLevel(logging.INFO)
logging.getLogger('routes.middleware')
self.map = mapper
self._router = routes.middleware.RoutesMiddleware(self._dispatch,

View File

@ -17,9 +17,9 @@
import webob
import webob.dec
from keystone.common import logging
from keystone.common import wsgi
from keystone import config
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils

View File

@ -15,12 +15,12 @@
# under the License.
from keystone.common import extension
from keystone.common import logging
from keystone.common import manager
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone import identity
from keystone.openstack.common import log as logging
from keystone import policy
from keystone import token

View File

@ -18,10 +18,10 @@ import copy
import uuid
from keystone.common import extension
from keystone.common import logging
from keystone.common import wsgi
from keystone import exception
from keystone import identity
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@ -82,7 +82,7 @@ class UserController(identity.controllers.User):
new_token_ref = copy.copy(token_ref)
new_token_ref['id'] = token_id
self.token_api.create_token(token_id, new_token_ref)
logging.debug('TOKEN_REF %s', new_token_ref)
LOG.debug('TOKEN_REF %s', new_token_ref)
return {'access': {'token': new_token_ref}}

View File

@ -15,10 +15,10 @@
# under the License.
from keystone.common import extension
from keystone.common import logging
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -17,10 +17,10 @@
"""Main entry point into the Credentials service."""
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -15,8 +15,8 @@
# under the License.
from keystone.common import config
from keystone.common import logging
from keystone.openstack.common.gettextutils import _ # noqa
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -21,12 +21,12 @@ import ldap
from keystone import clean
from keystone.common import dependency
from keystone.common import ldap as common_ldap
from keystone.common import logging
from keystone.common import models
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone import identity
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -22,10 +22,9 @@ import urlparse
import uuid
from keystone.common import controller
from keystone.common import logging
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF
DEFAULT_DOMAIN_ID = CONF.identity.default_domain_id

View File

@ -18,10 +18,10 @@
from keystone import clean
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -17,13 +17,12 @@
import webob.dec
from keystone.common import config
from keystone.common import logging
from keystone.common import serializer
from keystone.common import utils
from keystone.common import wsgi
from keystone import exception
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log as logging
CONF = config.CONF
LOG = logging.getLogger(__name__)

View File

@ -37,8 +37,8 @@ import httplib
import urllib
import webob
from keystone.common import logging
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log as logging
PROTOCOL_NAME = 'S3 Token Authentication'

View File

@ -19,10 +19,10 @@
import os.path
from keystone.common import logging
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
from keystone.openstack.common import policy as common_policy
from keystone import policy

View File

@ -14,19 +14,20 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
import routes
from keystone import assignment
from keystone import auth
from keystone import catalog
from keystone.common import dependency
from keystone.common import logging
from keystone.common import wsgi
from keystone import config
from keystone.contrib import ec2
from keystone import controllers
from keystone import credential
from keystone import identity
from keystone.openstack.common import log as logging
from keystone import policy
from keystone import routers
from keystone import token
@ -56,7 +57,23 @@ DRIVERS = dict(
dependency.resolve_future_dependencies()
@logging.fail_gracefully
def fail_gracefully(f):
"""Logs exceptions and aborts."""
@functools.wraps(f)
def wrapper(*args, **kw):
try:
return f(*args, **kw)
except Exception as e:
LOG.debug(e, exc_info=True)
# exception message is printed to all logs
LOG.critical(e)
exit(1)
return wrapper
@fail_gracefully
def public_app_factory(global_conf, **local_conf):
controllers.register_version('v2.0')
conf = global_conf.copy()
@ -68,7 +85,7 @@ def public_app_factory(global_conf, **local_conf):
routers.Extension(False)])
@logging.fail_gracefully
@fail_gracefully
def admin_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
@ -79,7 +96,7 @@ def admin_app_factory(global_conf, **local_conf):
routers.Extension()])
@logging.fail_gracefully
@fail_gracefully
def public_version_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
@ -87,7 +104,7 @@ def public_version_app_factory(global_conf, **local_conf):
[routers.Versions('public')])
@logging.fail_gracefully
@fail_gracefully
def admin_version_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
@ -95,7 +112,7 @@ def admin_version_app_factory(global_conf, **local_conf):
[routers.Versions('admin')])
@logging.fail_gracefully
@fail_gracefully
def v3_app_factory(global_conf, **local_conf):
controllers.register_version('v3')
conf = global_conf.copy()

View File

@ -40,7 +40,6 @@ from keystone import assignment
from keystone import catalog
from keystone.common import dependency
from keystone.common import kvs
from keystone.common import logging
from keystone.common import sql
from keystone.common import utils
from keystone.common import wsgi
@ -49,6 +48,7 @@ from keystone.contrib import ec2
from keystone import credential
from keystone import exception
from keystone import identity
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils
from keystone import policy
from keystone import token
@ -68,9 +68,6 @@ CONF = config.CONF
cd = os.chdir
logging.getLogger('routes.middleware').level = logging.WARN
def rootdir(*p):
return os.path.join(ROOTDIR, *p)

View File

@ -17,8 +17,8 @@
import copy
from keystone.common import kvs
from keystone.common import logging
from keystone import exception
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils
from keystone import token

View File

@ -19,11 +19,11 @@ import copy
import memcache
from keystone.common import logging
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils
from keystone import token

View File

@ -3,10 +3,10 @@ import json
from keystone.common import cms
from keystone.common import controller
from keystone.common import dependency
from keystone.common import logging
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils
from keystone.token import core
from keystone.token import provider as token_provider

View File

@ -21,10 +21,10 @@ import datetime
from keystone.common import cms
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils

View File

@ -18,10 +18,10 @@
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF

View File

@ -20,9 +20,9 @@ import json
from keystone.common import cms
from keystone.common import environment
from keystone.common import logging
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
from keystone.token.providers import uuid

View File

@ -2,10 +2,10 @@ import uuid
from keystone.common import controller
from keystone.common import dependency
from keystone.common import logging
from keystone import config
from keystone import exception
from keystone import identity
from keystone.openstack.common import log as logging
from keystone.openstack.common import timeutils

View File

@ -17,10 +17,10 @@
"""Main entry point into the Identity service."""
from keystone.common import dependency
from keystone.common import logging
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common import log as logging
CONF = config.CONF