Some changes in classes

This commit is contained in:
Christian
2024-08-18 11:57:38 +02:00
parent 0bbe702f8a
commit fb55785db1
8 changed files with 89 additions and 23 deletions

View File

@@ -2,19 +2,28 @@ import time
class log(object):
def __init__(self, logfile:str) -> None:
__logfile = logfile
__filehandle = None
self.__logfile = logfile
self.__filehandle = None
try:
self.__filehandle = open(self.logfile, "w")
except FileExistsError:
print("Datei existiert bereits...")
if(len(self.__logfile) >= 3):
try:
self.__filehandle = open(self.__logfile, "w")
except FileExistsError:
print("Datei existiert bereits...")
except:
print("Something went wrong!")
except:
print("Something went wrong!")
elif(len(self.__logfile) == 0):
print("No logfile!")
else:
print("Logfile needs to bo longer then 3 digits!")
def writeln(self, text:str):
self.__filehandle.writelines(F"{time.strftime("%H:%M:%S")}: {text}")
try:
self.__filehandle.writelines(F"{time.strftime("%H:%M:%S")}: {text} \n")
except:
print("[Log] Something went wrong on write line to logfile!")
def __del__(self):
self.writeln("Log closed!")