-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessages.py
More file actions
30 lines (25 loc) · 859 Bytes
/
Copy pathmessages.py
File metadata and controls
30 lines (25 loc) · 859 Bytes
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
28
29
30
from colorama import Fore, Style, init
from datetime import datetime
init(autoreset=True)
def log(message: str, level: str = "info") -> str:
"""
Returns a timestamped, colored log string.
Levels:
success -> [+] (green)
info -> [*] (cyan)
warn -> [!] (yellow)
error -> [-] (red)
"""
level = level.lower()
time_tag = datetime.now().strftime("%H:%M:%S")
if level == "success":
tag = Fore.GREEN + "[+]" + Style.RESET_ALL
elif level == "info":
tag = Fore.CYAN + "[*]" + Style.RESET_ALL
elif level == "warn":
tag = Fore.YELLOW + "[!]" + Style.RESET_ALL
elif level == "error":
tag = Fore.RED + "[-]" + Style.RESET_ALL
else:
tag = Fore.WHITE + "[?]" + Style.RESET_ALL
return f"{Fore.MAGENTA}[{time_tag}]{Style.RESET_ALL} {tag} {message}"