Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Enable logging of SQL statements #212

Merged
merged 2 commits into from
Apr 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/deployment/@relengapi/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ 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 verbose query logging.
To do so, set ``SQLALCHEMY_DB_LOG = True``.
Note that this output is *very* verbose and may severely impact site performance.

.. _Deployment-Authentication:

Authentication
Expand Down Expand Up @@ -130,19 +134,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': "<dn for bind user>",
'login_password': "<password for bind user>",

# 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 ``<everyone>`` is treated specially: it grants permission to all authenticated users, regardless of authentication mechanism.
Expand Down
8 changes: 8 additions & 0 deletions relengapi/lib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from sqlalchemy.orm import scoping
from sqlalchemy.pool import Pool


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -81,6 +82,13 @@ def _get_db_config(self, dbname):

@synchronized(threading.Lock())
def engine(self, dbname):
# Set the log level for db logs
sqla_logger = logging.getLogger('sqlalchemy.engine')
if self.app.config.get('SQLALCHEMY_DB_LOG', False):
sqla_logger.setLevel(logging.INFO)
else:
sqla_logger.setLevel(logging.WARNING)

if dbname not in self._engines:
uri = self._get_db_config(dbname)
self._engines[dbname] = engine = sa.create_engine(uri)
Expand Down
3 changes: 3 additions & 0 deletions settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# configuration is present, is to use '*.db' files in the directory containing
# the RelengAPI source code.

# set to True to log SQLAlchemy engine activities (very verbose!)
# SQLALCHEMY_DB_LOG = False

# ===== Authentication and Authorization =====

RELENGAPI_AUTHENTICATION = {
Expand Down