Created
April 4, 2023 00:47
-
-
Save GGontijo/faba4dc55de01a1532f9926cbde9a04f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
class Logger(): | |
def log_time() -> str: | |
return datetime.now().strftime("%d/%m/%Y %H:%M:%S") | |
def log_date() -> str: | |
return datetime.now().strftime("%d_%m_%Y") | |
def log(level, message) -> str: | |
match level: | |
case 'Info': | |
log_message = '\033[92m' + f'{Logger.log_time()} {level}: {message}' + '\033[0;0m\n' | |
case 'Alert': | |
log_message = '\033[31m' + f'{Logger.log_time()} {level}: {message}' + '\033[0;0m\n' | |
print(log_message) | |
if not FileExistsError: | |
with open(f'{Logger.log_date()}.txt', 'a') as f: | |
f.write(f'{log_message}\n') | |
else: | |
with open(f'{Logger.log_date()}.txt', 'w') as f: | |
f.write(f'{log_message}\n') | |
return log_message | |
Logger.log('Alert', 'teste') | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment