PgDB: fix connect() return and improve logging
This commit is contained in:
parent
64c2db5d5d
commit
198d6021b4
1 changed files with 17 additions and 8 deletions
13
PgDB.py
13
PgDB.py
|
@ -28,11 +28,20 @@ class PgDB(object):
|
|||
def connect(self):
|
||||
if self.con == 0:
|
||||
try:
|
||||
con = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (self.db,self.user,self.host,self.pwd))
|
||||
con = psycopg2.connect(
|
||||
dbname=self.db,
|
||||
user=self.user,
|
||||
host=self.host,
|
||||
password=self.pwd
|
||||
)
|
||||
self.con = con
|
||||
except Exception:
|
||||
logging.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):
|
||||
if self.con:
|
||||
|
|
Loading…
Reference in a new issue