File size: 905 Bytes
dbe0ac5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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') |