Skip to content

Commit 58f9cee

Browse files
committed
improve logging
1 parent c4c0b96 commit 58f9cee

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

testgres/testgres.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def pg_ctl(self, command, params={}, command_options=[]):
417417
def start(self, params={}):
418418
""" Starts cluster """
419419

420+
# choose log_filename
420421
if self.use_logging:
421422
tmpfile = tempfile.NamedTemporaryFile('w', dir=self.logs_dir, delete=False)
422423
log_filename = tmpfile.name
@@ -425,33 +426,37 @@ def start(self, params={}):
425426
else:
426427
log_filename = os.path.join(self.logs_dir, "postgresql.log")
427428

429+
# choose conf_filename
430+
conf_filename = os.path.join(self.data_dir, 'postgresql.conf')
431+
428432
_params = {
429433
"-D": self.data_dir,
430434
"-w": None,
431435
"-l": log_filename,
432436
}
433437
_params.update(params)
438+
434439
try:
435440
self.pg_ctl("start", _params)
436441
except ClusterException as e:
442+
def print_log_file(log_file):
443+
if os.path.exists(log_file):
444+
with open(log_filename, 'r') as logfile:
445+
print(logfile.read())
446+
else:
447+
print("File not found: {}".format(log_file))
448+
449+
# show pg_ctl LOG
437450
print("\npg_ctl log:\n----")
438451
print(str(e))
439-
if os.path.exists(log_filename):
440-
print("\npostgresql.log:\n----")
441-
with open(log_filename, 'r') as logfile:
442-
text = logfile.readlines()[-1]
443-
print(text)
444-
else:
445-
print("Log file not found: %s", log_filename)
446-
447-
conf_filename = os.path.join(self.data_dir, 'postgresql.conf')
448-
if os.path.exists(conf_filename):
449-
print("\npostgresql.conf:\n----")
450-
with open(conf_filename, 'r') as conffile:
451-
text = conffile.readlines()[-1]
452-
print(text)
453-
else:
454-
print("Configuration file not found: %s", conf_filename)
452+
453+
# show postmaster LOG
454+
print("\n{}:\n----".format(log_filename))
455+
print_log_file(log_filename)
456+
457+
# show CONFIG
458+
print("\n{}:\n----".format(conf_filename))
459+
print_log_file(conf_filename)
455460

456461
raise ClusterException("Couldn't start the new node")
457462

0 commit comments

Comments
 (0)