Add debug sqlalchemy logs (disabled by default)

This commit is contained in:
Piotr F. Mieszkowski 2024-01-08 22:45:59 +01:00
parent cd67b0934e
commit 55a369df83
2 changed files with 8 additions and 4 deletions

View file

@ -26,7 +26,7 @@ else:
def _no_database():
print('Database unavailable or not configured properly')
exit(lacre.EX_CONFIG)
sys.exit(lacre.EX_CONFIG)
def sub_queue(args):

View file

@ -17,17 +17,17 @@ _HOUR_IN_SECONDS = 3600
_engine = None
def init_engine(url):
def init_engine(url, db_debug=False):
global _engine
if not _engine:
config = _conn_config()
config = _conn_config(db_debug)
_engine = create_engine(url, **config)
return _engine
def _conn_config():
def _conn_config(db_debug):
config = dict()
mode = PoolingMode.from_config('database', 'pooling_mode', required=True)
@ -45,6 +45,10 @@ def _conn_config():
if config_item_set('database', 'max_overflow'):
config['max_overflow'] = int(get_item('database', 'max_overflow'))
if db_debug:
config['echo'] = 'debug'
config['echo_pool'] = 'debug'
LOG.debug('Database engine configuration: %s', config)
return config