From 640334893d34a03fe78914d5ba9b31f7585b8d09 Mon Sep 17 00:00:00 2001 From: Tlams Date: Thu, 12 Apr 2018 17:07:50 +0100 Subject: [PATCH] - Test log dir. --- code/scripts/main/core/libs/logs.py | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/code/scripts/main/core/libs/logs.py b/code/scripts/main/core/libs/logs.py index f0698d7..0fc8824 100644 --- a/code/scripts/main/core/libs/logs.py +++ b/code/scripts/main/core/libs/logs.py @@ -113,17 +113,21 @@ class Logger2: text = "[{date}] {info} : {text} \n".format(date=date, info=info, text=text) - if json_text["type"] == "PROXMOX": - errorlog = open("{0}/proxmox.log".format(self.logs_dir), "ab") - errorlog.write(text.encode('utf-8')) - elif json_text["type"] == "HYPERPROXMOX": - errorlog = open("{0}/hyperproxmox.log".format(self.logs_dir), "ab") - errorlog.write(text.encode('utf-8')) - elif json_text["type"] == "PYTHON": - errorlog = open("{0}/python.log".format(self.logs_dir), "ab") - errorlog.write(text.encode('utf-8')) - else: - errorlog = open("{0}/others.log".format(self.logs_dir), "ab") - errorlog.write(text.encode('utf-8')) + try: + if json_text["type"] == "PROXMOX": + errorlog = open("{0}/proxmox.log".format(self.logs_dir), "ab") + errorlog.write(text.encode('utf-8')) + elif json_text["type"] == "HYPERPROXMOX": + errorlog = open("{0}/hyperproxmox.log".format(self.logs_dir), "ab") + errorlog.write(text.encode('utf-8')) + elif json_text["type"] == "PYTHON": + errorlog = open("{0}/python.log".format(self.logs_dir), "ab") + errorlog.write(text.encode('utf-8')) + else: + errorlog = open("{0}/others.log".format(self.logs_dir), "ab") + errorlog.write(text.encode('utf-8')) + errorlog.close() + except BaseException: + print("Cannot write on {0}, please check permissions.".format(self.logs_dir)) + exit(1) - errorlog.close()