PgDB: fix connect() return and improve logging

This commit is contained in:
Benjamin Renard 2021-07-12 12:18:29 +02:00
parent 51dd4f5724
commit 6e778a8691

View file

@ -36,14 +36,19 @@ class PgDB:
if self.con == 0:
try:
con = psycopg2.connect(
"dbname='%s' user='%s' host='%s' password='%s'" % (
self.db, self.user, self.host, self.pwd
)
dbname=self.db,
user=self.user,
host=self.host,
password=self.pwd
)
self.con = con
except Exception:
log.fatal('An error occured during Postgresql database connection.', exc_info=1)
logging.fatal(
'An error occured during Postgresql database connection (%s@%s, database=%s).',
self.user, self.host, self.db, exc_info=1
)
sys.exit(1)
return True
def close(self):
""" Close connection with PostgreSQL server (if opened) """