| class Logger: | |
| def __init__(self, log_file): | |
| self.log_file = log_file | |
| # check if log file exixts else create it | |
| try: | |
| with open(self.log_file, 'r') as f: | |
| pass | |
| except: | |
| with open(self.log_file, 'w') as f: | |
| f.write('') | |
| def getTimeStamp(self): | |
| from datetime import datetime | |
| return datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
| def logError(self, message): | |
| with open(self.log_file, 'a') as f: | |
| f.write(f'[ERROR] @ [{self.getTimeStamp()}] {message}\n') | |
| def logInfo(self, message): | |
| with open(self.log_file, 'a') as f: | |
| f.write(f'[INFO] @ [{self.getTimeStamp()}] {message}\n') | |
| def logWarning(self, message): | |
| with open(self.log_file, 'a') as f: | |
| f.write(f'[WARNING] @ [{self.getTimeStamp()}] {message}\n') |