From 0403f1c27f8beec411ad5993ead00bac61a287f9 Mon Sep 17 00:00:00 2001 From: Rahul Ranjan Date: Thu, 29 Jan 2015 03:33:35 +0530 Subject: [PATCH] add SQLALCHEMY_LOG_FLAG remove trailing spaces new logger add sqlalchemy flag echo_pool for sqlalchemy logging remove typo error update sqlalchemy log correct indentation remove print statement update sqlalchemy logging --- docs/deployment/@relengapi/config.rst | 10 ++++++---- relengapi/lib/db.py | 7 +++++++ settings_example.py | 6 ++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/deployment/@relengapi/config.rst b/docs/deployment/@relengapi/config.rst index 86410614..3909358c 100644 --- a/docs/deployment/@relengapi/config.rst +++ b/docs/deployment/@relengapi/config.rst @@ -28,6 +28,8 @@ This is effective for development, but certainly not for production. The database for the relengapi core is named ``relengapi``. Other blueprints may require additional URIs. +If you ever need to see what SQLAlchemy is doing with the connection pool, it is useful to enable the logging. To do that make sure you have the ``SQLALCHEMY_DB_LOG`` is flag to set to True. + .. _Deployment-Authentication: Authentication @@ -130,19 +132,19 @@ The configuration looks like this:: # Base LDAP URI 'uri': "ldaps://your.ldap.server/", - + # This needs to be a user that has sufficient rights to read users and groups 'login_dn': "", 'login_password': "", - + # The search bases for users and groups, respectively 'user_base': 'o=users,dc=example,dc=com', 'group_base': 'o=groups,dc=example,dc=com', - + # set this to True for extra logging 'debug': False, } - + Permissions are cumulative: a person has a permission if they are a member of any group configured with that permission. In the example above, a user in both ``team_relops`` and ``team_releng`` would have permission to create tasks and to issue and view tokens. The group name ```` is treated specially: it grants permission to all authenticated users, regardless of authentication mechanism. diff --git a/relengapi/lib/db.py b/relengapi/lib/db.py index 665a78bf..30a0c7b8 100644 --- a/relengapi/lib/db.py +++ b/relengapi/lib/db.py @@ -18,7 +18,10 @@ from sqlalchemy.orm import scoping from sqlalchemy.pool import Pool + +# db logging logger = logging.getLogger(__name__) +logging.basicConfig() class _QueryProperty(object): @@ -75,6 +78,10 @@ def _get_db_config(self, dbname): @synchronized(threading.Lock()) def engine(self, dbname): + # Get the log level for db logs + if self.app.config.get('SQLALCHEMY_DB_LOG'): + logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) + if dbname not in self._engines: uri = self._get_db_config(dbname) self._engines[dbname] = sa.create_engine(uri) diff --git a/settings_example.py b/settings_example.py index 99e3dba9..b1a4cf57 100644 --- a/settings_example.py +++ b/settings_example.py @@ -15,6 +15,10 @@ # configuration is present, is to use '*.db' files in the directory containing # the RelengAPI source code. +# set the flag True for logging SQLAlchemy engine activities +# default it is set to True +SQLALCHEMY_DB_LOG = True + # ===== Authentication and Authorization ===== RELENGAPI_AUTHENTICATION = { @@ -36,3 +40,5 @@ # ===== Celery ===== # Any Celery configuration option can be included here; see # http://docs.celeryproject.org/en/master/configuration.html#configuration + +