diff --git a/docs/deployment/@relengapi/config.rst b/docs/deployment/@relengapi/config.rst index f0530243..2846ddd3 100644 --- a/docs/deployment/@relengapi/config.rst +++ b/docs/deployment/@relengapi/config.rst @@ -28,7 +28,9 @@ 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. +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: diff --git a/relengapi/lib/db.py b/relengapi/lib/db.py index 020a1064..5eea1e0e 100644 --- a/relengapi/lib/db.py +++ b/relengapi/lib/db.py @@ -21,9 +21,7 @@ from sqlalchemy.pool import Pool -# db logging logger = logging.getLogger(__name__) -logging.basicConfig() class _QueryProperty(object): @@ -84,9 +82,12 @@ 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) + # 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) diff --git a/settings_example.py b/settings_example.py index 95dc5f25..3480b702 100644 --- a/settings_example.py +++ b/settings_example.py @@ -15,9 +15,8 @@ # 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 +# set to True to log SQLAlchemy engine activities (very verbose!) +# SQLALCHEMY_DB_LOG = False # ===== Authentication and Authorization =====