-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
30 lines (23 loc) · 950 Bytes
/
logger.py
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
import logging
# Set up logging to a file with custom formatting and timestamp
logging.basicConfig(filename='logfile.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
def log_to_file(prefix, message):
logging.info(f"{prefix}: {message}")
def colored(r, g, b, text):
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
def print_error(message):
formatted_message = colored(255, 0, 0, message)
print(formatted_message)
log_to_file("ERROR", message)
def print_warn(message):
formatted_message = colored(255, 255, 0, message)
print(formatted_message)
log_to_file("WARN", message)
def print_info(message):
formatted_message = colored(0, 255, 0, message)
print(formatted_message)
log_to_file("INFO", message)
def print_misc(message):
formatted_message = colored(255, 255, 255, message)
print(formatted_message)
log_to_file("MISC", message)